Open yildiz opened 4 years ago
I also found the same issue, it's not like usual. i used PHP 7.2.24
I get the same error. Any progress on issue fix?
Yes, looks like Pinterest has changed something in their API. Any help is appreciated. Feel free to debug and provide a PR 🙏
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.
I did something out and managed to make a new user.
Delete cookies file
Register 'email@provider.com'
error with 'length'
DON'T delete cookies
Register 'email@provider.com' (The same email as before)
error 'Email already taken.'
I think this proves that the problem should be cookie related rather than pinterest api related
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();
}
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.
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?
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 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.
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();
}
I encountered an issue with the following code:
Library version: ^5.9
PHP version: 7.2.20
I expected to get:
But I actually get:
Thanks!