seregazhuk / php-pinterest-bot

This PHP library will help you to work with your Pinterest account without using any API account credentials.
MIT License
414 stars 129 forks source link

Can not create an account #484

Open yildiz opened 4 years ago

yildiz commented 4 years ago

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!

alterolo commented 4 years ago

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

sineld commented 4 years ago

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

seregazhuk commented 4 years ago

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

kkristof200 commented 4 years ago

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 commented 4 years ago

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

  1. Delete cookies file

  2. Register 'email@provider.com'

  3. error with 'length'

  4. DON'T delete cookies

  5. Register 'email@provider.com' (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 commented 4 years ago

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

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();
}
kaankilic commented 4 years ago

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.

yildiz commented 4 years ago

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?

Minhnguyendhth8b commented 4 years ago

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' => "{}"
        ];
    }
kaankilic commented 4 years ago

@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.

SezerFidanci commented 4 years ago

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('randommail@gmail.com', 'pasword123', 'Test Name');
        $registration
            ->setAge(27)
            ->setCountry('GB')
            ->setMaleGender();

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