postaddictme / instagram-php-scraper

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

Response code is 403: Forbidden #1100

Closed naveedumar786 closed 1 year ago

naveedumar786 commented 1 year ago

InstagramScraper\Exception\InstagramAuthException Response code is 403: Forbidden.

Unable to find the solution...

NabiKAZ commented 1 year ago
PHP Fatal error:  Uncaught InstagramScraper\Exception\InstagramAuthException: Response code is 403: Forbidden.Something went wrong. Please report issue. in C:\Nabi\instagram-php-scraper\vendor\raiym\instagram-php-scraper\src\InstagramScraper\Instagram.php:2229
Stack trace:
#0 C:\Nabi\instagram-php-scraper\save_medias.php(70): InstagramScraper\Instagram->login(true, Object(InstagramScraper\TwoStepVerification\ConsoleVerification))
#1 {main}
  thrown in C:\Nabi\instagram-php-scraper\vendor\raiym\instagram-php-scraper\src\InstagramScraper\Instagram.php on line 2229
hbranco commented 1 year ago

nstagramScraper\Exception\InstagramAuthException: Response code is 403: Forbidden.Something went wrong. Please report issue. in file C:\.......\back\vendor\raiym\instagram-php-scraper\src\InstagramScraper\Instagram.php on line 2229

username and password is correctly.

hbranco commented 1 year ago

nstagramScraper\Exception\InstagramAuthException: Response code is 403: Forbidden.Something went wrong. Please report issue. in file C:\.......\back\vendor\raiym\instagram-php-scraper\src\InstagramScraper\Instagram.php on line 2229

username and password is correctly.

fverdicchio commented 1 year ago

PHP Fatal error: Uncaught InstagramScraper\Exception\InstagramAuthException: Response code is 403: Forbidden.Something went wrong. Please report issue. in /home/....../projects/wineexp-scraper/vendor/raiym/instagram-php-scraper/src/InstagramScraper/Instagram.php:2229 Stack trace:

0 /home/.......index.php(18): InstagramScraper\Instagram->login()

1 {main}

thrown in /home/........./vendor/raiym/instagram-php-scraper/src/InstagramScraper/Instagram.php on line 2229

i'm having same problem

reza305z commented 1 year ago

Same issue here. Xampp and VPN on localhost

NabiKAZ commented 1 year ago

I noticed that the following error appears on the web version as well:

CSRF token missing or incorrect

And there is a 403 error in the console:

Request URL: https://www.instagram.com/api/v1/web/accounts/login/ajax/
Request Method: POST
Status Code: 403
{"message":"CSRF token missing or incorrect","status":"fail"}

After a little research I came up with this solution:

Open your chrome browser developer tools then go to the login page of instagram, in the network tab find request that goes like this https://www.instagram.com/ click on the request and in the response tab press ctrl+f and search for csrf_token, copy the value of csrf go the application tab, in storage section click on cookies and insert a cookie with csrftoken name and paste the value and make it secure. now fill the login form and press enter. hope it helps ref: https://stackoverflow.com/a/74372169/1407491

This method works for entering the web version. I think this trick can solve the problem of this package.

NabiKAZ commented 1 year ago

I worked on the topic more.

First I noticed in this line:

https://github.com/postaddictme/instagram-php-scraper/blob/adfb322888f70a527e99ddc97b8e52fb1a914545/src/InstagramScraper/Instagram.php#L2213

There is a bug and it should be like this:

preg_match('/\\\\"csrf_token\\\\":\\\\"(.*?)\\\\"/', $response->body, $match);

Then the previous 403 problem was solved.

But this time the problem was with the two-step login, which I noticed that the previous version of Instagram and of course some current challenges still use the window._sharedData... format:

image

That the code related to it also exists on the same basis:

https://github.com/postaddictme/instagram-php-scraper/blob/adfb322888f70a527e99ddc97b8e52fb1a914545/src/InstagramScraper/Instagram.php#L2365

But with Instagram's recent changes, its HTML and JS source has been obfuscated and looks like this:

image

Therefore, there is a need for optimization and correction in this field.

alexwebck commented 7 months ago

It seems that the issue is still reproduced: Fatal error: Uncaught InstagramScraper\Exception\InstagramAuthException: Response code is 403: Forbidden.Something went wrong. Please report issue. in /sandbox/instagram/src/InstagramScraper/Instagram.php:2244

Works only with the sessionId, but not with the login and password.