From 472acbc938be8b51204202e282d3c902272fa015 Mon Sep 17 00:00:00 2001 From: Pierre Grimaud Date: Mon, 18 May 2020 17:12:23 +0200 Subject: [PATCH] Add temporary workaround for login #670 --- src/InstagramScraper/Instagram.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/InstagramScraper/Instagram.php b/src/InstagramScraper/Instagram.php index acfa9462..16edd5f2 100644 --- a/src/InstagramScraper/Instagram.php +++ b/src/InstagramScraper/Instagram.php @@ -241,10 +241,10 @@ private function generateHeaders($session, $gisToken = null) $headers['x-instagram-gis'] = $gisToken; } } - + if (empty($headers['x-csrftoken'])) { $headers['x-csrftoken'] = md5(uniqid()); // this can be whatever, insta doesn't like an empty value - } + } return $headers; } @@ -745,7 +745,7 @@ public function getMediaCommentsByCode($code, $count = 10, $maxId = null) $commentsUrl = Endpoints::getCommentsBeforeCommentIdByCode($variables); $response = Request::get($commentsUrl, $this->generateHeaders($this->userSession, $this->generateGisToken($variables))); - + if (static::HTTP_OK !== $response->code) { throw new InstagramException('Response code is ' . $response->code . '. Body: ' . static::getErrorBody($response->body) . ' Something went wrong. Please report issue.', $response->code); } @@ -774,7 +774,7 @@ public function getMediaCommentsByCode($code, $count = 10, $maxId = null) $comments[] = Comment::create($commentArray['node']); $index++; } - + if ($count > $numberOfComments) { $count = $numberOfComments; } @@ -1256,7 +1256,7 @@ public function getLocationById($facebookLocationId) return Location::create($jsonResponse['graphql']['location']); } - + /** * @param string $accountId Account id of the profile to query * @param int $count Total followers to retrieve @@ -1319,7 +1319,7 @@ public function getPaginateFollowers($accountId, $count = 20, $pageSize = 20, $d if (count($edgesArray) === 0) { throw new InstagramException('Failed to get followers of account id ' . $accountId . '. The account is private.', static::HTTP_FORBIDDEN); } - + foreach ($edgesArray as $edge) { $accounts[] = $edge['node']; $index++; @@ -1342,7 +1342,7 @@ public function getPaginateFollowers($accountId, $count = 20, $pageSize = 20, $d } } $toReturn = [ - 'hasNextPage' => $lastPagingInfo['has_next_page'], + 'hasNextPage' => $lastPagingInfo['has_next_page'], 'nextPage' => $lastPagingInfo['end_cursor'], 'accounts' => $accounts ]; @@ -1435,8 +1435,8 @@ public function getPaginateFollowing($accountId, $count = 20, $pageSize = 20, $d } } $toReturn = [ - 'hasNextPage' => $lastPagingInfo['has_next_page'], - 'nextPage' => $lastPagingInfo['end_cursor'], + 'hasNextPage' => $lastPagingInfo['has_next_page'], + 'nextPage' => $lastPagingInfo['end_cursor'], 'accounts' => $accounts ]; return $toReturn; @@ -1545,7 +1545,7 @@ public function login($force = false, $twoStepVerificator = null) 'user-agent' => $this->getUserAgent(), ]; $response = Request::post(Endpoints::LOGIN_URL, $headers, - ['username' => $this->sessionUsername, 'password' => $this->sessionPassword]); + ['username' => $this->sessionUsername, 'enc_password' => '#PWD_INSTAGRAM_BROWSER:0:' . time() . ':' . $this->sessionPassword]); if ($response->code !== static::HTTP_OK) { if (