Skip to content

Commit

Permalink
getPaginateMedias() fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ezobraz committed Nov 9, 2017
1 parent b87f7df commit 6384e74
Showing 1 changed file with 5 additions and 4 deletions.
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

0 comments on commit 6384e74

Please sign in to comment.