Hello,
First of all, I've applied #290 .
Problem occurs when requesting 'next page' with getPaginateMedias() function.
I passed username and maxId, and it returned $medias array with 12 most recent items.
I presume this problem also caused by the recent change with Instagram JSON.
From my test, Instagram will now ignore maxId.
Thanks, @eos1d3
I've changed the Request url with after instead of maxId, it seems working.
~~~php
public function getPaginateMedias($username, $maxId = '')
{
$account = $this->getAccount($username);
$hasNextPage = true;
$medias = [];
$toReturn = [
'medias' => $medias,
'maxId' => $maxId,
'hasNextPage' => $hasNextPage,
];
//$response = Request::get(Endpoints::getAccountMediasJsonLink($username, $maxId), $this->generateHeaders($this->userSession));
$response = Request::get("https://instagram.com/graphql/query/?query_id=17888483320059182&id=".$account->getId()."&first=12&after=".$maxId, $this->generateHeaders($this->userSession));
// use a raw constant in the code is not a good idea!!
//if ($response->code !== 200) {
if (static::HTTP_OK !== $response->code) {
throw new InstagramException('Response code is ' . $response->code . '. Body: ' . static::getErrorBody($response->body) . ' Something went wrong. Please report issue.');
}
$arr = json_decode($response->raw_body, true, 512, JSON_BIGINT_AS_STRING);
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['data']['user']['edge_owner_to_timeline_media']['edges'];
//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($nodes)) {
return $toReturn;
}
foreach ($nodes as $mediaArray) {
$medias[] = Media::create($mediaArray['node']);
}
$maxId = $arr['data']['user']['edge_owner_to_timeline_media']['page_info']['end_cursor'];
$hasNextPage = $arr['data']['user']['edge_owner_to_timeline_media']['page_info']['has_next_page'];
$toReturn = [
'medias' => $medias,
'maxId' => $maxId,
'hasNextPage' => $hasNextPage,
];
return $toReturn;
}
~~~
Yes, this works. The value of 'after' can also be the idin node. idand end_cursorboth work for end cursor.
Using query_id=17888483320059182 request, as the same in current hot fix, has tighter rate limit. Your IP will be blocked for around 3 minutes if the same request reach around 60 times or more per minute. While the old one (?__a=1) will block for around 10-15 seconds.
Thanks again @eos1d3
I came back to ask about that rate limit issue.
I'll try the old one.
The old one works only for first 12 Instagram. There is no way to retrieve more than this limit.
Currently only GraphQL request can support cursor.
Weird thing, it still working with tags :
https://www.instagram.com/explore/tags/cats/?__a=1
https://www.instagram.com/explore/tags/cats/?__a=1&max_id=1736283239527868244
馃
Thanks for the pagination URL update. I'm using PowerShell to do this, and discovered that IG made some changes to the JSON objects as well that reference posts.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Most helpful comment
Yes, this works. The value of 'after' can also be the
idinnode.idandend_cursorboth work for end cursor.Using
query_id=17888483320059182request, as the same in current hot fix, has tighter rate limit. Your IP will be blocked for around 3 minutes if the same request reach around 60 times or more per minute. While the old one (?__a=1) will block for around 10-15 seconds.