Skip to content

Commit

Permalink
Merge pull request #1 from congkv/hotfix/fatal_error
Browse files Browse the repository at this point in the history
Fix fatal error <Undefined index: has_next_page>
  • Loading branch information
congkv authored Aug 11, 2020
2 parents 6bd0ea3 + 4dbb893 commit 03139e0
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions src/InstagramScraper/Instagram.php
Original file line number Diff line number Diff line change
Expand Up @@ -1315,18 +1315,24 @@ 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++;
if ($index >= $count) {
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;
}

Expand Down Expand Up @@ -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++;
Expand All @@ -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;
}

Expand Down

0 comments on commit 03139e0

Please sign in to comment.