postaddictme / instagram-php-scraper

Get account information, photos, videos, stories and comments.
https://packagist.org/packages/raiym/instagram-php-scraper
MIT License
3.07k stars 800 forks source link

Response code is 401: Unauthorized. Something went wrong. Please report issue. (In production) #1097

Closed wdda closed 1 year ago

wdda commented 1 year ago

Hello! When I use the library on the local docker server everything works fine, but on the VPS I get an error when trying to get a profile. Using a proxy didn't help. The login method cannot establish the correct session. Instagram returns an empty "Set-Cookie" parameter in the headers.

$guzzle = new Client(['https://scraperapi:secret@proxy-server.scraperapi.com:8001']);
$this->api = Instagram::withCredentials(
    $guzzle,
    $this->account->login,
    $this->account->password,
    new Psr16Adapter('Files')
);

$this->api->login(true);
$this->api->getAccountInfo($username); // Response code is 401: Unauthorized. Something went wrong. Please report issue. 

dd($headers, $response);

On the local server (docker):

array:5 [ // packages/instagram-php-scraper/src/InstagramScraper/Instagram.php:2228
  "cookie" => "ig_cb=1; csrftoken=UFU68l84JB0PywMrHa83R6dG9BZPH8sY; mid=Y05RtwAEAAFTE3CRk20ck-oYfUak"
  "referer" => "https://www.instagram.com/"
  "x-csrftoken" => "UFU68l84JB0PywMrHa83R6dG9BZPH8sY"
  "X-CSRFToken" => "UFU68l84JB0PywMrHa83R6dG9BZPH8sY"
  "user-agent" => "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 Safari/537.36"
]
InstagramScraper\Http\Response {#1407 // packages/instagram-php-scraper/src/InstagramScraper/Instagram.php:2228
  +code: 200
  +raw_body: "{"user":true,"userId":"55617188423","authenticated":true,"oneTapPrompt":true,"status":"ok"}"
  +body: {#1405
    +"user": true
    +"userId": "55617188423"
    +"authenticated": true
    +"oneTapPrompt": true
    +"status": "ok"
  }
  +headers: array:32 [
    "Content-Type" => array:1 [
      0 => "application/json; charset=utf-8"
    ]
    "ig-set-password-encryption-web-key-id" => array:1 [
      0 => "75"
    ]
    "ig-set-password-encryption-web-pub-key" => array:1 [
      0 => "af35bd57ef2bde00e06f489bb26cee7eadf7d7129ba191c78898174548f07e55"
    ]
    "ig-set-password-encryption-web-key-version" => array:1 [
      0 => "10"
    ]
    "x-robots-tag" => array:1 [
      0 => "noindex"
    ]
    "Vary" => array:1 [
      0 => "Cookie, Accept-Language"
    ]
    "Date" => array:1 [
      0 => "Tue, 18 Oct 2022 07:12:01 GMT"
    ]
    "Strict-Transport-Security" => array:1 [
      0 => "max-age=31536000"
    ]
    "Content-Language" => array:1 [
      0 => "en"
    ]
    "Cache-Control" => array:1 [
      0 => "private, no-cache, no-store, must-revalidate"
    ]
    "Pragma" => array:1 [
      0 => "no-cache"
    ]
    "Expires" => array:1 [
      0 => "Sat, 01 Jan 2000 00:00:00 GMT"
    ]
    "X-Frame-Options" => array:1 [
      0 => "SAMEORIGIN"
    ]
    "content-security-policy" => array:1 [
      0 => "report-uri https://www.instagram.com/security/csp_report/; default-src 'self' https://www.instagram.com; img-src data: blob: https://*.fbcdn.net https://*.instagram.com https://*.cdninstagram.com https://*.facebook.com https://*.fbsbx.com https://*.giphy.com; font-src data: https://*.fbcdn.net https://*.instagram.com https://*.cdninstagram.com; media-src 'self' blob: https://www.instagram.com https://*.cdninstagram.com https://*.fbcdn.net; manifest-src 'self' https://www.instagram.com; script-src 'self' https://instagram.com https://www.instagram.com https://*.www.instagram.com https://*.cdninstagram.com wss://www.instagram.com https://*.facebook.com https://*.fbcdn.net https://*.facebook.net 'unsafe-inline' 'unsafe-eval' blob:; style-src 'self' https://*.www.instagram.com https://www.instagram.com 'unsafe-inline'; connect-src 'self' https://instagram.com https://www.instagram.com https://*.www.instagram.com https://graph.instagram.com https://*.graph.instagram.com https://i.instagram.com/graphql_www https://graphql.instagram.com https://*.cdninstagram.com https://api.instagram.com https://i.instagram.com https://*.i.instagram.com https://*.od.instagram.com wss://www.instagram.com wss://edge-chat.instagram.com https://*.facebook.com https://*.fbcdn.net https://*.facebook.net chrome-extension://boadgeojelhgndaghljhdicfkmllpafd blob:; worker-src 'self' blob: https://www.instagram.com; frame-src 'self' https://instagram.com https://www.instagram.com https://*.instagram.com https://staticxx.facebook.com https://www.facebook.com https://web.facebook.com https://connect.facebook.net https://m.facebook.com https://*.fbsbx.com; object-src 'none'; upgrade-insecure-requests"
    ]
    "cross-origin-embedder-policy-report-only" => array:1 [
      0 => "require-corp;report-to="coep""
    ]
    "report-to" => array:1 [
      0 => "{"group": "coep", "max_age": 86400, "endpoints": [{"url": "/security/coep_report/"}]},{"group": "coop", "max_age": 86400, "endpoints": [{"url": "/security/coop_report/"}]}"
    ]
    "cross-origin-resource-policy" => array:1 [
      0 => "cross-origin"
    ]
    "origin-trial" => array:1 [
      0 => "AuqWincgAuXeuu3KypEMnrrFEJHySaesyJS3EaIH40zvafzrU0Irhb7+5QwZpOqMZrPTjgvFl7Z5jJgy1dNAcQMAAAB6eyJvcmlnaW4iOiJodHRwczovL2luc3RhZ3JhbS5jb206NDQzIiwiZmVhdHVyZSI6IkNyb3NzT3JpZ2luT3BlbmVyUG9saWN5UmVwb3J0aW5nIiwiZXhwaXJ5IjoxNjEzNDExNjYyLCJpc1N1YmRvbWFpbiI6dHJ1ZX0="
    ]
    "cross-origin-opener-policy" => array:1 [
      0 => "same-origin-allow-popups;report-to="coop""
    ]
    "X-Content-Type-Options" => array:1 [
      0 => "nosniff"
    ]
    "X-XSS-Protection" => array:1 [
      0 => "0"
    ]
    "x-ig-push-state" => array:1 [
      0 => "c2"
    ]
    "x-aed" => array:1 [
      0 => "72"
    ]
    "Access-Control-Expose-Headers" => array:1 [
      0 => "X-IG-Set-WWW-Claim"
    ]
    "x-ig-request-elapsed-time-ms" => array:1 [
      0 => "9831"
    ]
    "x-ig-peak-time" => array:1 [
      0 => "0"
    ]
    "Set-Cookie" => array:13 [
      0 => "csrftoken=S0GgS2PCXIngY4NS7eBegxIBdJLQLwFR; Domain=.instagram.com; expires=Tue, 17-Oct-2023 07:12:01 GMT; Max-Age=31449600; Path=/; Secure"
      1 => "rur="CLN\05455617188423\0541697613121:01f76a82bd8380e8fb771913cfdb91d706d73a3244cd3c48a3475306541def74eac7cfb7"; Domain=.instagram.com; HttpOnly; Path=/; Secure"
      2 => "sessionid=55617188423%3AjhISgjzLwCYRiz%3A3%3AAYeR49KesxPb6-kjtddv4V_PTMXt9RSDdMRMlyl1QQ; Domain=.instagram.com; expires=Wed, 18-Oct-2023 07:12:01 GMT; HttpOnly; Max-Age=31536000; Path=/; Secure"
      3 => "ig_did=EBCCFDF1-4AE5-4631-A734-E2EE90318C05; Domain=.instagram.com; expires=Thu, 17-Oct-2024 07:12:01 GMT; HttpOnly; Max-Age=63072000; Path=/; Secure"
      4 => "ig_nrcb=1; Domain=.instagram.com; expires=Wed, 18-Oct-2023 07:12:01 GMT; Max-Age=31536000; Path=/; Secure"
      5 => "ds_user_id=55617188423; Domain=.instagram.com; expires=Mon, 16-Jan-2023 07:12:01 GMT; Max-Age=7776000; Path=/; Secure"
      6 => "ig_cb=""; Domain=instagram.com; expires=Thu, 01-Jan-1970 00:00:00 GMT; Max-Age=0; Path=/"
      7 => "ig_cb=""; Domain=.instagram.com; expires=Thu, 01-Jan-1970 00:00:00 GMT; Max-Age=0; Path=/"
      8 => "ig_cb=""; Domain=i.instagram.com; expires=Thu, 01-Jan-1970 00:00:00 GMT; Max-Age=0; Path=/"
      9 => "ig_cb=""; Domain=.i.instagram.com; expires=Thu, 01-Jan-1970 00:00:00 GMT; Max-Age=0; Path=/"
      10 => "ig_cb=""; Domain=www.instagram.com; expires=Thu, 01-Jan-1970 00:00:00 GMT; Max-Age=0; Path=/"
      11 => "ig_cb=""; Domain=.www.instagram.com; expires=Thu, 01-Jan-1970 00:00:00 GMT; Max-Age=0; Path=/"
      12 => "ig_cb=""; expires=Thu, 01-Jan-1970 00:00:00 GMT; Max-Age=0; Path=/"
    ]
    "x-ig-origin-region" => array:1 [
      0 => "cln"
    ]
    "X-FB-TRIP-ID" => array:1 [
      0 => "1679558926"
    ]
    "Alt-Svc" => array:1 [
      0 => "h3=":443"; ma=86400"
    ]
    "Connection" => array:1 [
      0 => "keep-alive"
    ]
    "Content-Length" => array:1 [
      0 => "91"
    ]
  ]
}

In production (VPS):

array:5 [ // packages/instagram-php-scraper/src/InstagramScraper/Instagram.php:2228
  "cookie" => "ig_cb=1; csrftoken=2GC5LyJUMqTc8jN6ZOcmGG8krHljscJU; mid=Y05SVgAEAAHzYcdZNbWtZ9sXCI83"
  "referer" => "https://www.instagram.com/"
  "x-csrftoken" => "2GC5LyJUMqTc8jN6ZOcmGG8krHljscJU"
  "X-CSRFToken" => "2GC5LyJUMqTc8jN6ZOcmGG8krHljscJU"
  "user-agent" => "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 Safari/537.36"
]
InstagramScraper\Http\Response {#1407 // packages/instagram-php-scraper/src/InstagramScraper/Instagram.php:2228
  +code: 200
  +raw_body: "{"user":true,"userId":"55948991158","authenticated":true,"oneTapPrompt":true,"status":"ok"}"
  +body: {#1405
    +"user": true
    +"userId": "55948991158"
    +"authenticated": true
    +"oneTapPrompt": true
    +"status": "ok"
  }
  +headers: array:32 [
    "Content-Type" => array:1 [
      0 => "application/json; charset=utf-8"
    ]
    "ig-set-password-encryption-web-key-id" => array:1 [
      0 => "75"
    ]
    "ig-set-password-encryption-web-pub-key" => array:1 [
      0 => "af35bd57ef2bde00e06f489bb26cee7eadf7d7129ba191c78898174548f07e55"
    ]
    "ig-set-password-encryption-web-key-version" => array:1 [
      0 => "10"
    ]
    "x-robots-tag" => array:1 [
      0 => "noindex"
    ]
    "Vary" => array:1 [
      0 => "Cookie, Accept-Language"
    ]
    "Date" => array:1 [
      0 => "Tue, 18 Oct 2022 07:14:37 GMT"
    ]
    "Strict-Transport-Security" => array:1 [
      0 => "max-age=31536000"
    ]
    "Content-Language" => array:1 [
      0 => "en"
    ]
    "Cache-Control" => array:1 [
      0 => "private, no-cache, no-store, must-revalidate"
    ]
    "Pragma" => array:1 [
      0 => "no-cache"
    ]
    "Expires" => array:1 [
      0 => "Sat, 01 Jan 2000 00:00:00 GMT"
    ]
    "X-Frame-Options" => array:1 [
      0 => "SAMEORIGIN"
    ]
    "content-security-policy" => array:1 [
      0 => "report-uri https://www.instagram.com/security/csp_report/; default-src 'self' https://www.instagram.com; img-src data: blob: https://*.fbcdn.net https://*.instagram.com https://*.cdninstagram.com https://*.facebook.com https://*.fbsbx.com https://*.giphy.com; font-src data: https://*.fbcdn.net https://*.instagram.com https://*.cdninstagram.com; media-src 'self' blob: https://www.instagram.com https://*.cdninstagram.com https://*.fbcdn.net; manifest-src 'self' https://www.instagram.com; script-src 'self' https://instagram.com https://www.instagram.com https://*.www.instagram.com https://*.cdninstagram.com wss://www.instagram.com https://*.facebook.com https://*.fbcdn.net https://*.facebook.net 'unsafe-inline' 'unsafe-eval' blob:; style-src 'self' https://*.www.instagram.com https://www.instagram.com 'unsafe-inline'; connect-src 'self' https://instagram.com https://www.instagram.com https://*.www.instagram.com https://graph.instagram.com https://*.graph.instagram.com https://i.instagram.com/graphql_www https://graphql.instagram.com https://*.cdninstagram.com https://api.instagram.com https://i.instagram.com https://*.i.instagram.com https://*.od.instagram.com wss://www.instagram.com wss://edge-chat.instagram.com https://*.facebook.com https://*.fbcdn.net https://*.facebook.net chrome-extension://boadgeojelhgndaghljhdicfkmllpafd blob:; worker-src 'self' blob: https://www.instagram.com; frame-src 'self' https://instagram.com https://www.instagram.com https://*.instagram.com https://staticxx.facebook.com https://www.facebook.com https://web.facebook.com https://connect.facebook.net https://m.facebook.com https://*.fbsbx.com; object-src 'none'; upgrade-insecure-requests"
    ]
    "cross-origin-embedder-policy-report-only" => array:1 [
      0 => "require-corp;report-to="coep""
    ]
    "report-to" => array:1 [
      0 => "{"group": "coep", "max_age": 86400, "endpoints": [{"url": "/security/coep_report/"}]},{"group": "coop", "max_age": 86400, "endpoints": [{"url": "/security/coop_report/"}]}"
    ]
    "cross-origin-resource-policy" => array:1 [
      0 => "cross-origin"
    ]
    "origin-trial" => array:1 [
      0 => "AuqWincgAuXeuu3KypEMnrrFEJHySaesyJS3EaIH40zvafzrU0Irhb7+5QwZpOqMZrPTjgvFl7Z5jJgy1dNAcQMAAAB6eyJvcmlnaW4iOiJodHRwczovL2luc3RhZ3JhbS5jb206NDQzIiwiZmVhdHVyZSI6IkNyb3NzT3JpZ2luT3BlbmVyUG9saWN5UmVwb3J0aW5nIiwiZXhwaXJ5IjoxNjEzNDExNjYyLCJpc1N1YmRvbWFpbiI6dHJ1ZX0="
    ]
    "cross-origin-opener-policy" => array:1 [
      0 => "same-origin-allow-popups;report-to="coop""
    ]
    "X-Content-Type-Options" => array:1 [
      0 => "nosniff"
    ]
    "X-XSS-Protection" => array:1 [
      0 => "0"
    ]
    "x-ig-push-state" => array:1 [
      0 => "c2"
    ]
    "x-aed" => array:1 [
      0 => "72"
    ]
    "Access-Control-Expose-Headers" => array:1 [
      0 => "X-IG-Set-WWW-Claim"
    ]
    "x-ig-request-elapsed-time-ms" => array:1 [
      0 => "6337"
    ]
    "x-ig-peak-time" => array:1 [
      0 => "0"
    ]
    "Set-Cookie" => array:22 [
      0 => "csrftoken=""; Domain=instagram.com; expires=Thu, 01-Jan-1970 00:00:00 GMT; Max-Age=0; Path=/"
      1 => "csrftoken=""; Domain=.instagram.com; expires=Thu, 01-Jan-1970 00:00:00 GMT; Max-Age=0; Path=/"
      2 => "csrftoken=""; Domain=i.instagram.com; expires=Thu, 01-Jan-1970 00:00:00 GMT; Max-Age=0; Path=/"
      3 => "csrftoken=""; Domain=.i.instagram.com; expires=Thu, 01-Jan-1970 00:00:00 GMT; Max-Age=0; Path=/"
      4 => "csrftoken=""; Domain=www.instagram.com; expires=Thu, 01-Jan-1970 00:00:00 GMT; Max-Age=0; Path=/"
      5 => "csrftoken=""; Domain=.www.instagram.com; expires=Thu, 01-Jan-1970 00:00:00 GMT; Max-Age=0; Path=/"
      6 => "csrftoken=""; expires=Thu, 01-Jan-1970 00:00:00 GMT; Max-Age=0; Path=/"
      7 => "mid=""; Domain=instagram.com; expires=Thu, 01-Jan-1970 00:00:00 GMT; Max-Age=0; Path=/"
      8 => "mid=""; Domain=.instagram.com; expires=Thu, 01-Jan-1970 00:00:00 GMT; Max-Age=0; Path=/"
      9 => "mid=""; Domain=i.instagram.com; expires=Thu, 01-Jan-1970 00:00:00 GMT; Max-Age=0; Path=/"
      10 => "mid=""; Domain=.i.instagram.com; expires=Thu, 01-Jan-1970 00:00:00 GMT; Max-Age=0; Path=/"
      11 => "mid=""; Domain=www.instagram.com; expires=Thu, 01-Jan-1970 00:00:00 GMT; Max-Age=0; Path=/"
      12 => "mid=""; Domain=.www.instagram.com; expires=Thu, 01-Jan-1970 00:00:00 GMT; Max-Age=0; Path=/"
      13 => "mid=""; expires=Thu, 01-Jan-1970 00:00:00 GMT; Max-Age=0; Path=/"
      14 => "ds_user_id=55948991158; Domain=.instagram.com; expires=Mon, 16-Jan-2023 07:14:37 GMT; Max-Age=7776000; Path=/; Secure"
      15 => "ig_cb=""; Domain=instagram.com; expires=Thu, 01-Jan-1970 00:00:00 GMT; Max-Age=0; Path=/"
      16 => "ig_cb=""; Domain=.instagram.com; expires=Thu, 01-Jan-1970 00:00:00 GMT; Max-Age=0; Path=/"
      17 => "ig_cb=""; Domain=i.instagram.com; expires=Thu, 01-Jan-1970 00:00:00 GMT; Max-Age=0; Path=/"
      18 => "ig_cb=""; Domain=.i.instagram.com; expires=Thu, 01-Jan-1970 00:00:00 GMT; Max-Age=0; Path=/"
      19 => "ig_cb=""; Domain=www.instagram.com; expires=Thu, 01-Jan-1970 00:00:00 GMT; Max-Age=0; Path=/"
      20 => "ig_cb=""; Domain=.www.instagram.com; expires=Thu, 01-Jan-1970 00:00:00 GMT; Max-Age=0; Path=/"
      21 => "ig_cb=""; expires=Thu, 01-Jan-1970 00:00:00 GMT; Max-Age=0; Path=/"
    ]
    "x-ig-origin-region" => array:1 [
      0 => "odn"
    ]
    "X-FB-TRIP-ID" => array:1 [
      0 => "1679558926"
    ]
    "Alt-Svc" => array:1 [
      0 => "h3=":443"; ma=86400"
    ]
    "Connection" => array:1 [
      0 => "keep-alive"
    ]
    "Content-Length" => array:1 [
      0 => "91"
    ]
  ]
}

It's been several days without results. Thank you for any help.

tanjed commented 1 year ago

@wdda Facing the same issue on the production. Would you please share something about how to resolve it?

wdda commented 1 year ago

@tanjed I specified the proxy settings incorrectly: $guzzle = new Client(['https://scraperapi:secret@proxy-server.scraperapi.com:8001']);

Correct settings: $guzzle = new Client(['proxy' => 'https://scraperapi:secret@proxy-server.scraperapi.com:8001']);

But it didn't help, I started getting 403 error like here: https://github.com/postaddictme/instagram-php-scraper/issues/1099

Even on a local server, without a proxy. Until a week ago, everything was working well.

tanjed commented 1 year ago

@wdda Followed the same settings but got Response code is 403: Forbidden.Something went wrong. Please report issue Here is the code :

$guzzle = new Client(['proxy' => 'http://scraperapi:'. $scraperApiSecret .'@proxy-server.scraperapi.com:8001','verify' => false]);
 $instagram = \InstagramScraper\Instagram::withCredentials($guzzle,$userName, $password,new Psr16Adapter('Files'));
 $instagram->login(true);