Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getPaginateMedias() fix #204

Merged
merged 1 commit into from
Nov 9, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/InstagramScraper/Instagram.php
Original file line number Diff line number Diff line change
Expand Up @@ -295,20 +295,21 @@ public function getPaginateMedias($username, $maxId = '')
if (!is_array($arr)) {
throw new InstagramException('Response code is ' . $response->code . '. Body: ' . static::getErrorBody($response->body) . ' Something went wrong. Please report issue.');
}
$nodes = $arr['user']['media']['nodes'];

//if (count($arr['items']) === 0) {
// I generally use empty. Im not sure why people would use count really - If the array is large then count takes longer/has more overhead.
// If you simply need to know whether or not the array is empty then use empty.
if (empty($arr['items'])) {
if (empty($nodes)) {
return $toReturn;
}

foreach ($arr['items'] as $mediaArray) {
foreach ($nodes as $mediaArray) {
$medias[] = Media::create($mediaArray);
}

$maxId = $arr['items'][count($arr['items']) - 1]['id'];
$hasNextPage = $arr['more_available'];
$maxId = $arr['user']['media']['page_info']['end_cursor'];
$hasNextPage = $arr['user']['media']['page_info']['has_next_page'];

$toReturn = [
'medias' => $medias,
Expand Down