diff --git a/src/Instagram/Auth/Login.php b/src/Instagram/Auth/Login.php index f5094b1..0129a14 100644 --- a/src/Instagram/Auth/Login.php +++ b/src/Instagram/Auth/Login.php @@ -70,8 +70,11 @@ public function process(): CookieJar $html = (string) $baseRequest->getBody(); - preg_match('/\"csrf_token\":\"(.*?)\"/', $html, $matches); + $pattern = '/{"csrf_token":"([^"]+)"}/'; + + preg_match($pattern, $html, $matches); + if (!isset($matches[1])) { throw new InstagramAuthException('Unable to extract JSON data'); } @@ -145,7 +148,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];