Reputation: 61
I am trying to solve challenges required from Instagram when I log in to my account, I am using mgp25 Instagram API library (V 4.1.0 stable)
I was able to sniff the necessary request in order to solve the challenge, But I am having problems when I add them to the library
I wrote this function to request the code to my email or phone
// Challenge url on this format /challenge/1463452997/1zS1L8kl62/
public function sendChallenge($challenge_url)
{
return $this->request($challenge_url)
->addParam('choice', 1)
->addPost('device_id', $this->device_id)
->addPost('guid', $this->uuid)
->addPost('_csrftoken', $this->client->getToken())
->getResponse(new Response\UserInfoResponse());
}
My problem is whenever I request this function no matter where I put it, I always get
"User not logged in. Please call login() and then try again."
so how can I use this function after a failed login ( necessary to retrieve the challenge url) without getting User not logged in exception
Upvotes: 4
Views: 24677
Reputation: 171
before you send request to instagram you must select who want to send you can add line bellow to your code and select user
// Challenge url on this format /challenge/1463452997/1zS1L8kl62/
public function sendChallenge($username, $password, $challenge_url)
{
//this line require for select user that your login in before
$this -> changeUser ($username, $password);
return $this->request($challenge_url)
->addParam('choice', 1)
->addPost('device_id', $this->device_id)
->addPost('guid', $this->uuid)
->addPost('_csrftoken', $this->client->getToken())
->getResponse(new Response\UserInfoResponse());
}
Upvotes: 0
Reputation: 41
This worked for me:
Steps:
Upvotes: 4
Reputation: 61
The solution was to set setNeedsAuth(false)
// Challenge url on this format /challenge/1463452997/1zS1L8kl62/
public function sendChallenge($challenge_url)
{
return $this->request($challenge_url)
->setNeedsAuth(false)
->addParam('choice', 1)
->addPost('device_id', $this->device_id)
->addPost('guid', $this->uuid)
->addPost('_csrftoken', $this->client->getToken())
->getResponse(new Response\UserInfoResponse());
}
Upvotes: 2