Skip to content

Commit 3dc5322

Browse files
authored
Merge pull request #37 from fabianoroberto/master
Handle pagination into getMediasByTag
2 parents 8d474a9 + 81de727 commit 3dc5322

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,19 @@ $medias = Instagram::getMediasByTag('zara', 30);
8787
echo json_encode($medias);
8888
```
8989

90+
### Paginate medias by tag name
91+
```php
92+
$result = Instagram::getMediasByTag('zara', 12, '', true);
93+
$medias = $result['medias']
94+
95+
if($result['hasNextPage'] === true) {
96+
$result = Instagram::getMediasByTag('zara', 12, $result['maxId'], true);
97+
$medias = array_merge($medias, $result['medias']);
98+
}
99+
100+
echo json_encode($medias);
101+
```
102+
90103
### Get top medias by tag name
91104
```php
92105
$medias = Instagram::getTopMediasByTagName('durov');

src/InstagramScraper/Instagram.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public static function getMediaByUrl($mediaUrl)
113113
return Media::fromMediaPage($mediaArray['media']);
114114
}
115115

116-
public static function getMediasByTag($tag, $count = 12, $maxId = '')
116+
public static function getMediasByTag($tag, $count = 12, $maxId = '', $toObject = false)
117117
{
118118
$index = 0;
119119
$medias = [];
@@ -145,7 +145,18 @@ public static function getMediasByTag($tag, $count = 12, $maxId = '')
145145
$maxId = $arr['tag']['media']['page_info']['end_cursor'];
146146
$hasNextPage = $arr['tag']['media']['page_info']['has_next_page'];
147147
}
148-
return $medias;
148+
149+
if($toObject === true) {
150+
$toReturn = [
151+
'medias' => $medias,
152+
'maxId' => $maxId,
153+
'hasNextPage' => $hasNextPage
154+
];
155+
} else {
156+
$toReturn = $medias;
157+
}
158+
159+
return $toReturn;
149160
}
150161

151162
public static function searchAccountsByUsername($username)

0 commit comments

Comments
 (0)