php-pinterest-bot icon indicating copy to clipboard operation
php-pinterest-bot copied to clipboard

Can not create an account

Open yildiz opened this issue 5 years ago • 11 comments

I encountered an issue with the following code:

<?php

	$registration = new Registration($user["email"], $user["pass"], $user["name"]);
	$registration
		->setAge($user["age"])
		->setCountry($user["cc"])
		->setFemaleGender();

	if($bot->auth->register($registration)){
		echo "ok";
	}else{
		$bot->getLastError();
	}

Library version: ^5.9

PHP version: 7.2.20

I expected to get:

"ok"

But I actually get:

Array (
  [status] => failure
  [http_status] => 500
  [code] => 51
  [message] => Cannot read property 'length' of undefined
)
 


Thanks!

yildiz avatar Nov 18 '19 03:11 yildiz

I also found the same issue, it's not like usual. i used PHP 7.2.24

alterolo avatar Nov 19 '19 03:11 alterolo

I get the same error. Any progress on issue fix?

sineld avatar Nov 19 '19 17:11 sineld

Yes, looks like Pinterest has changed something in their API. Any help is appreciated. Feel free to debug and provide a PR 🙏

seregazhuk avatar Nov 19 '19 20:11 seregazhuk

Hey. I've tries registering and it worked so the problem might not be with the API. However, when today I tried registering another user, I've got the error presented above. I've checked the response it contained the email, which I've used to register last time so I think there might be some cookies not deleted on new session.

kkristof200 avatar Nov 30 '19 18:11 kkristof200

I did something out and managed to make a new user.

  1. Delete cookies file

  2. Register '[email protected]'

  3. error with 'length'

  4. DON'T delete cookies

  5. Register '[email protected]' (The same email as before)

  6. error 'Email already taken.'

I think this proves that the problem should be cookie related rather than pinterest api related

kkristof200 avatar Nov 30 '19 19:11 kkristof200

I've found this 'workaround' to make it work. What I've found while testing:

  • Also $bot->auth->register($registration) returning true did not mean in all cases, that my acc was registered
  • the 'Cannot read property 'length' of undefined' error appeared randomly.

The 'workaround' code:

while ($current_retry < $max_retry) {
	$bot->getHttpClient()->removeCookies();
	$current_retry += 1;

	if ($bot->auth->register($registration)) {
		echo 'register_result: ok. Will try again to validate.' . PHP_EOL;
	} else {
		echo 'register_result: error' . PHP_EOL;
		$error = $bot->getLastError();
		echo 'last_error: \'' . $error . '\'' . PHP_EOL;
		
		if (contains('Email already taken.', (string)$error)) {
			return TRUE;
		}
	}

        rand_sleep();
}

kkristof200 avatar Dec 04 '19 09:12 kkristof200

I don't know there is any change on registration endpoint but the parameters below are not sent on the plugin.

	'signupSource'  => 'homePage',
	'hybridTier' 	=> 'open',
	'page'			=> 'home',

When I manually add the parameters to getData function on Registration class. it was worked without Invalid Parameter error. Now, it gives an invalid JSON error. Checked the code, json_encode works! the Invalid Json exception received on Pinterest response even the JSON has a valid structure.

kaankilic avatar Jan 17 '20 22:01 kaankilic

I don't know there is any change on registration endpoint but the parameters below are not sent on the plugin.

	'signupSource'  => 'homePage',
	'hybridTier' 	=> 'open',
	'page'			=> 'home',

When I manually add the parameters to getData function on Registration class. it was worked without Invalid Parameter error. Now, it gives an invalid JSON error. Checked the code, json_encode works! the Invalid Json exception received on Pinterest response even the JSON has a valid structure.

@kaankilic Have you be able to solve?

yildiz avatar Jan 29 '20 20:01 yildiz

The error is something like: Invalid JSON. And solution here is just update getData() function as @kaankilic mention above with minor change: 'visited_pages' => "[]", or just remove that parameter in getData() function. Like this:

public function getData()
    {
        return [
            'first_name'    => $this->name,
            'last_name'     => '',
            'email'         => $this->email,
            'password'      => $this->password,
            'age'           => $this->age,
            'country'       => $this->country,
            'container'     => 'home_page',
            'visited_pages' => "[]",
            'signupSource'  => 'homePage',
            'hybridTier' 	=> 'open',
            'page'			=> 'home',
            'user_behavior_data' => "{}"
        ];
    }

Minhnguyendhth8b avatar Jan 30 '20 07:01 Minhnguyendhth8b

@Minhnguyendhth8b Wow. it worked without any error or ghost ban. Thanks. Someone needs to create pr about that.

@volkany you can use the solution above. It worked me, when I changed it manually.

kaankilic avatar Jan 30 '20 16:01 kaankilic

Create new helpers class. Set name "RegistrationFix" and add the code below to this class.

use seregazhuk\PinterestBot\Api\Forms\Registration;

class RegistrationFix extends Registration
{

    /**
     * @var string
     */
    protected $email;

    /**
     * @var string
     */
    protected $password;

    /**
     * @var string
     */
    protected $name;

    /**
     * @var string
     */
    protected $country = 'GB';

    /**
     * @var string
     */
    protected $age = '18';

    /**
     * @var string
     */
    protected $gender = 'male';

    /**
     * @var string
     */
    protected $site;

    /**
     * @param string $email
     * @param string $password
     * @param string $name
     */
    public function __construct($email, $password, $name)
    {
        $this->email = $email;
        $this->password = $password;
        $this->name = $name;
    }

    /**
     * @param mixed $email
     * @return Registration
     */
    public function setEmail($email)
    {
        $this->email = $email;
        return $this;
    }

    /**
     * @param string $password
     * @return Registration
     */
    public function setPassword($password)
    {
        $this->password = $password;
        return $this;
    }

    /**
     * @param string $name
     * @return Registration
     */
    public function setName($name)
    {
        $this->name = $name;
        return $this;
    }

    /**
     * @param string $country
     * @return Registration
     */
    public function setCountry($country)
    {
        $this->country = $country;
        return $this;
    }

    /**
     * @param int $age
     * @return Registration
     */
    public function setAge($age)
    {
        // Pinterest requires age to be a string
        $this->age = (string)$age;
        return $this;
    }

    /**
     * @param string $gender
     * @return Registration
     */
    public function setGender($gender)
    {
        $this->gender = $gender;
        return $this;
    }

    /**
     * @return Registration
     */
    public function setMaleGender()
    {
        return $this->setGender('male');
    }

    /**
     * @return Registration
     */
    public function setFemaleGender()
    {
        return $this->setGender('female');
    }

    /**
     * @return array
     */
    public function getData()
    {
        return [
            'first_name'    => $this->name,
            'last_name'     => '',
            'email'         => $this->email,
            'password'      => $this->password,
            'age'           => $this->age,
            'country'       => $this->country,
            'container'     => 'home_page',
            'visited_pages' => "[]",
            'signupSource'  => 'homePage',
            'hybridTier' 	=> 'open',
            'page'			=> 'home',
            'user_behavior_data' => "{}"
        ];
    }

    /**
     * @param string $site
     * @return Registration
     */
    public function setSite($site)
    {
        $this->site = $site;
        return $this;
    }

    /**
     * @return string
     */
    public function getSite()
    {
        return $this->site;
    }
}

and use it that way

$bot = PinterestBot::create();
$registration = new RegistrationFix('[email protected]', 'pasword123', 'Test Name');
       $registration
           ->setAge(27)
           ->setCountry('GB')
           ->setMaleGender();



       if($bot->auth->register($registration)){
           echo "ok";
       }else{
           echo $bot->getLastError();
       }

SezerFidanci avatar Mar 12 '20 09:03 SezerFidanci