From ce39b814a37ed4e36d53311a9dbe7b19b5707ed1 Mon Sep 17 00:00:00 2001 From: deepvision7 Date: Sat, 24 Feb 2024 14:58:29 +0200 Subject: [PATCH] Fixes the loginWithCookies "Please login with instagram credentials" error --- src/Instagram/Auth/Login.php | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/Instagram/Auth/Login.php b/src/Instagram/Auth/Login.php index 28916e1..e6b6fed 100644 --- a/src/Instagram/Auth/Login.php +++ b/src/Instagram/Auth/Login.php @@ -70,7 +70,7 @@ public function process(): CookieJar $html = (string) $baseRequest->getBody(); - preg_match('/\\\"csrf_token\\\":\\\"(.*?)\\\"/', $html, $matches); + preg_match('/\"csrf_token\":\"(.*?)\"/', $html, $matches); if (!isset($matches[1])) { throw new InstagramAuthException('Unable to extract JSON data'); @@ -145,14 +145,10 @@ public function withCookies(array $session): CookieJar $html = (string) $baseRequest->getBody(); - preg_match('/\\\"csrf_token\\\":\\\"(.*?)\\\"/', $html, $matches); + preg_match('/\"csrf_token\":\"(.*?)\"/', $html, $matches); - if (isset($matches[1])) { - $data = $matches[1]; - - if (!isset($data->config->viewer) && !isset($data->config->viewerId)) { - throw new InstagramAuthException('Please login with instagram credentials.'); - } + if (!isset($matches[1])) { + throw new InstagramAuthException('Unable to extract JSON data'); } return $cookies;