postaddictme / instagram-php-scraper

Get account information, photos, videos, stories and comments.

Home Page:https://packagist.org/packages/raiym/instagram-php-scraper

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

hammadev opened this issue · comments

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

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