4

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

martin bayen
  • 61
  • 1
  • 1
  • 5

3 Answers3

4

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.
Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
2

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());
}
martin bayen
  • 61
  • 1
  • 1
  • 5
  • that's amazing, but how i can get the challenge url?! for the logged in user which require to do the challenge?! – TheBlueDragon May 09 '19 at 20:19
  • 1
    @TheBlueDragon Did you solve the problem? Where do I need to put that function?? – Digerkam Oct 12 '19 at 21:50
  • Was just wondering if you guys have solved the issue? I assume the function should be placed in Instagram.php. Am I correct? I've managed to get the $challenge_url through https://github.com/mgp25/Instagram-API/issues/2130#issuecomment-410073192 But can't figure out how I should proceed with the $challenge_url with code above. If anyone could help, that'd be very appreciated! – Andre W. Oct 24 '19 at 18:46
0

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());
}
shahab
  • 171
  • 2
  • 11
  • is this function placed in Instagram.php? If so, does it mean we need to fork the repo to make the changes as it's not the best practice to changes files in th vendor folder? I'm asking in the context of a Laravel project. Thanks! – Andre W. Oct 24 '19 at 19:22