instagram-php-scraper: Getting error 400 Bad request

It was working very well till later today I started to get this error:

Fatal error: Uncaught InstagramScraper\Exception\InstagramAuthException: Response code is 400. Body: Bad request Something went wrong. Please report issue. in /home2/hamzadiaz/public_html/instagram/vendor/raiym/instagram-php-scraper/src/InstagramScraper/Instagram.php:1664 Stack trace: #0 /home2/hamzadiaz/public_html/instagram/profile.php(26): InstagramScraper\Instagram->login() #1 {main} thrown in /home2/hamzadiaz/public_html/instagram/vendor/raiym/instagram-php-scraper/src/InstagramScraper/Instagram.php on line 1664

I tried using different Instagram account for login but getting same error. Here is what line 1664 Instagram.php of code has:

} elseif ((is_string($response->code) || is_numeric($response->code)) && is_string($response->body)) {
    throw new InstagramAuthException('Response code is ' . $response->code . '. Body: ' . $response->body . ' Something went wrong. Please report issue.', $response->code);
}

Can’t figure out how to get it fixed, Maybe Instagram made some update?

Thanks in advance

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 43 (5 by maintainers)

Commits related to this issue

Most upvoted comments

I published a workaround on my scrapper. It seems working for me, some people could try it : https://github.com/pgrimaud/instagram-user-feed/commit/96ad4cf54d1ad331b337f325c73e664999a6d066 ?

Just clone my repository, edit this file and run it.

If it will conclusive, I will open a PR on this repository.

Thanks for tests and feedback 😄

for checkpoint_required

Short solution is to create new account

i search on the internet to fix challenge, it need to Temporarily disable account, i do this for old account, and maybe wait 3days or 1 week, before enabling again.

I published a workaround on my scrapper. It seems working for me, some people could try it : pgrimaud/instagram-user-feed@96ad4cf ?

Just clone my repository, edit this file and run it.

If it will conclusive, I will open a PR on this repository.

Thanks for tests and feedback 😄

Thank you so much @pgrimaud!!! I changed Login() function of Instagram.php file to your approach and now I no longer get error 400 Bad Request:

 $headers = [
                'cookie' => $cookieString,
                'referer' => Endpoints::BASE_URL . '/',
                'x-csrftoken' => $csrfToken,
                'X-CSRFToken' => $csrfToken,
                'user-agent' => $this->getUserAgent(),
            ];
            $response = Request::post(Endpoints::LOGIN_URL, $headers,
                ['username' => $this->sessionUsername, 'enc_password' => '#PWD_INSTAGRAM_BROWSER:0:' . time() . ':' . $this->sessionPassword]);

We need to find a way to generate enc_password form field value.

Got the same error on my scraper too : https://github.com/pgrimaud/instagram-user-feed/issues/65

I found this, which could help us : https://www.bountysource.com/issues/87593270-add-enc_password-header-for-requests-version

I’m actually working on it. If someone has good knowledge about crypto in JavaScript (AES), please contact me.

@jangrewe hehe sorry i never thought UA important, after getting this error again, i try to change it, and it works,

just debugging thing, sometimes try to hardcode 😅

thanks for mention the function 😃

I have been getting the 200 error as well. I tried to comment out line 385 and I even though I no longer get the error I also can not access any images. This is what I get on sentry

Response code is 200. Body: <!DOCTYPE html>

<html lang="en" class="no-js not-logged-in client-root touch"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>

Login • Instagram

</title>
    <meta name="robots" content="noimageindex, noarchive">
    <meta name="apple-mobile-web-app-status-bar-style" content="default">
    <meta name="mobile-web-app-capable" content="yes">
    <meta name="theme-color" content="#ffffff">
    <meta id="viewport" name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, viewport-fit=cover">
    <link rel="manifest" href="/data/manifest.json">

    <link rel="preload" href="/static/bundles/es6/ConsumerUICommons.css/f642bd753a44.css" as="style" type="text/css" crossorigin="anonymous" />
<link rel="preload" href="/static/bundles/es6/ConsumerAsyncCommons.css/638f1bd337c8.css" as="style" type="text/css" crossorigin="anonymous" />
  • I published a workaround on my scrapper. It seems working for me, some people could try it : pgrimaud/instagram-user-feed@96ad4cf ? Just clone my repository, edit this file and run it. If it will conclusive, I will open a PR on this repository. Thanks for tests and feedback 😄

    Thank you so much @pgrimaud!!! I changed Login() function of Instagram.php file to your approach and now I no longer get error 400 Bad Request:

     $headers = [
                    'cookie' => $cookieString,
                    'referer' => Endpoints::BASE_URL . '/',
                    'x-csrftoken' => $csrfToken,
                    'X-CSRFToken' => $csrfToken,
                    'user-agent' => $this->getUserAgent(),
                ];
                $response = Request::post(Endpoints::LOGIN_URL, $headers,
                    ['username' => $this->sessionUsername, 'enc_password' => '#PWD_INSTAGRAM_BROWSER:0:' . time() . ':' . $this->sessionPassword]);
    

    it works using this

    But I need to create new account

    Old account always ask confirmation everytime script running

    i try to change variable password to enc_password

    https://github.com/postaddictme/instagram-php-scraper/blob/6503db29f6bfbf36bbd281da88f73fda279033f5/src/InstagramScraper/Instagram.php#L1540-L1548

    $headers = [
                    'ig-set-password-encryption-web-key-id' => 33,
                    'ig-set-password-encryption-web-pub-key' => '0d85544e7b7b43e0e4465d0a35690925cc7c53c04dc07a6fbffdb45be2718c52',
                    'ig-set-password-encryption-web-key-version' => 10,
                    'cookie' => $cookieString,
                    'referer' => Endpoints::BASE_URL . '/',
                    'x-csrftoken' => $csrfToken,
                    'X-CSRFToken' => $csrfToken,
                    'user-agent' => $this->getUserAgent(),
                ];
                $response = Request::post(Endpoints::LOGIN_URL, $headers,
                    ['username' => $this->sessionUsername, 'enc_password' => $this->sessionPassword,'optIntoOneTap'=>false]);
    

    but got respond like this

    {“code”:400,“raw_body”:“{"message": "checkpoint_required", "checkpoint_url": "/challenge/6242737647/GMoK4dsqH9/", "lock": false, "status": "fail"}”,“body”:{“message”:“checkpoint_required”,“checkpoint_url”:“/challenge/6242737647/GMoK4dsqH9/”,“lock”:false,“status”:“fail”}

    using encoded password from browser login

    and then confirmation show up Jepretan Layar 2020-05-17 pukul 19 10 30