diff --git a/src/InstagramScraper/Instagram.php b/src/InstagramScraper/Instagram.php index 7a490b9..cacad86 100644 --- a/src/InstagramScraper/Instagram.php +++ b/src/InstagramScraper/Instagram.php @@ -2210,7 +2210,7 @@ class Instagram throw new InstagramException('Response code is ' . $response->code . ': ' . static::httpCodeToString($response->code) . '.' . 'Something went wrong. Please report issue.', $response->code, static::getErrorBody($response->body)); } - preg_match('/\\\\"csrf_token\\\\":\\\\"(.*?)\\\\"/', $response->body, $match); + preg_match('/csrftoken=(.*?);/', $response->headers['Set-Cookie'][0], $match); $csrfToken = isset($match[1]) ? $match[1] : ''; $cookies = $this->parseCookies($response->headers); @@ -2219,6 +2219,8 @@ class Instagram $cookieString = 'ig_cb=1'; if ($csrfToken !== '') { $cookieString .= '; csrftoken=' . $csrfToken; + } else { + throw new InstagramException('csrftoken is empty. Most probably Instagram changed the place of it or the namespace. Without it, login is failing.'); } if ($mid !== '') { $cookieString .= '; mid=' . $mid;