postaddictme / instagram-php-scraper

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

Response code is 403: Forbidden.Something went wrong. Please report issue. at this line $instagram->login(); #1132

Open hammadev opened 10 months ago

hammadev commented 10 months ago

Got Response code is 403: Forbidden.Something went wrong. Please report issue. at this line $instagram->login();

here's my code $username = ''; $password = ''; $instagram = \InstagramScraper\Instagram::withCredentials(new \GuzzleHttp\Client(), $username, $password, new Psr16Adapter('Files')); // dd($instagram); $instagram->login(); // will use cached session if you want to force login $instagram->login(true) $instagram->saveSession(); //DO NOT forget this in order to save the session, otherwise have no sense $account = $instagram->getAccountById(3); echo $account->getUsername();

here's my response for dd($instagram); image

anraetsky commented 10 months ago

It seems that Instagram changed a lot of things.

If you are on last version 0.12.9 and after debug you get error in line 2242 from src/InstagramScraper/Instagram.php then you may fix the issue with this changes Change preg_match('/\\\\"csrf_token\\\\":\\\\"(.*?)\\\\"/', $response->body, $match); To: preg_match('/csrftoken=(.*?);/', $response->headers['Set-Cookie'][0], $match); Or see diff from attached file (could be used as patch if replace the extension to .patch): login.txt