From 3c5410fa8982ef5e4806fb3426d7d62761c611f7 Mon Sep 17 00:00:00 2001 From: sohagsrz Date: Sun, 31 Dec 2023 06:51:59 +0600 Subject: [PATCH 1/2] fix extract json issue --- src/Instagram/Auth/Login.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Instagram/Auth/Login.php b/src/Instagram/Auth/Login.php index f5094b1..72e2236 100644 --- a/src/Instagram/Auth/Login.php +++ b/src/Instagram/Auth/Login.php @@ -70,8 +70,12 @@ public function process(): CookieJar $html = (string) $baseRequest->getBody(); - preg_match('/\"csrf_token\":\"(.*?)\"/', $html, $matches); + $pattern = '/{"csrf_token":"([^"]+)"}/'; + + preg_match($pattern, $html, $matches); + + var_dump($matches); if (!isset($matches[1])) { throw new InstagramAuthException('Unable to extract JSON data'); } @@ -145,7 +149,7 @@ 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]; From 195fe4573f889efdda45ea548a216aae1201ca7d Mon Sep 17 00:00:00 2001 From: sohagsrz Date: Sun, 31 Dec 2023 06:53:13 +0600 Subject: [PATCH 2/2] fix extract json issue --- src/Instagram/Auth/Login.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Instagram/Auth/Login.php b/src/Instagram/Auth/Login.php index 72e2236..0129a14 100644 --- a/src/Instagram/Auth/Login.php +++ b/src/Instagram/Auth/Login.php @@ -74,8 +74,7 @@ public function process(): CookieJar preg_match($pattern, $html, $matches); - - var_dump($matches); + if (!isset($matches[1])) { throw new InstagramAuthException('Unable to extract JSON data'); }