From 4dbb893da3fe74396f8cf2dec56b445499868d3c Mon Sep 17 00:00:00 2001 From: Khuong Van Cong Date: Fri, 7 Aug 2020 17:23:48 +0700 Subject: [PATCH] fix fatal error --- src/InstagramScraper/Instagram.php | 31 ++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/src/InstagramScraper/Instagram.php b/src/InstagramScraper/Instagram.php index 744dfd58..a49b7011 100644 --- a/src/InstagramScraper/Instagram.php +++ b/src/InstagramScraper/Instagram.php @@ -1315,6 +1315,15 @@ public function getPaginateFollowers($accountId, $count = 20, $pageSize = 20, $d throw new InstagramException('Failed to get followers of account id ' . $accountId . '. The account is private.', static::HTTP_FORBIDDEN); } + $pageInfo = $jsonResponse['data']['user']['edge_followed_by']['page_info']; + $lastPagingInfo = $pageInfo; + if ($pageInfo['has_next_page']) { + $endCursor = $pageInfo['end_cursor']; + $hasNextPage = true; + } else { + $hasNextPage = false; + } + foreach ($edgesArray as $edge) { $accounts[] = $edge['node']; $index++; @@ -1322,11 +1331,8 @@ public function getPaginateFollowers($accountId, $count = 20, $pageSize = 20, $d break 2; } } - $pageInfo = $jsonResponse['data']['user']['edge_followed_by']['page_info']; - $lastPagingInfo = $pageInfo; - if ($pageInfo['has_next_page']) { - $endCursor = $pageInfo['end_cursor']; - } else { + + if (!$hasNextPage) { break; } @@ -1407,6 +1413,15 @@ public function getPaginateFollowing($accountId, $count = 20, $pageSize = 20, $d throw new InstagramException('Failed to get followers of account id ' . $accountId . '. The account is private.', static::HTTP_FORBIDDEN); } + $pageInfo = $jsonResponse['data']['user']['edge_follow']['page_info']; + $lastPagingInfo = $pageInfo; + if ($pageInfo['has_next_page']) { + $endCursor = $pageInfo['end_cursor']; + $hasNextPage = true; + } else { + $hasNextPage = false; + } + foreach ($edgesArray as $edge) { $accounts[] = $edge['node']; $index++; @@ -1415,11 +1430,7 @@ public function getPaginateFollowing($accountId, $count = 20, $pageSize = 20, $d } } - $pageInfo = $jsonResponse['data']['user']['edge_follow']['page_info']; - $lastPagingInfo = $pageInfo; - if ($pageInfo['has_next_page']) { - $endCursor = $pageInfo['end_cursor']; - } else { + if (!$hasNextPage) { break; }