Solving challenge required in instagram private api

23.1k Views Asked by At

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

3

There are 3 best solutions below

0
On

This worked for me:

Steps:

  1. Have google chrome or install google chrome cause its what I did it on
  2. Go to instagram.com and in your address bar it should now show www.instagram.com/challenge/ or something similar.
  3. This is were you will delete cookies from this site to stop them from replaying the same error message over and over... even if you have the right sms code. Go to step 4!
  4. Click green lock button(website security verification) in your address bar (top left on screen) and go to site settings.
  5. Once there click the back button in the setting option NOT the actual back button to take you to your previous webpage but the little arrow button to go back in the setting.
  6. Then click cookies option
  7. Then click "see all cookies and site data"
  8. "Search cookie" should show in the search bar in the top right
  9. Search Instagram and all your cookies come up
  10. Delete ALL cookies and go back to instagram.com
  11. Finished and should let you log in hopefully.
3
On

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());
}
1
On

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());
}