cosenary / Instagram-PHP-API

An easy-to-use PHP Class for accessing Instagram's API.
http://cosenary.github.com/Instagram-PHP-API
BSD 3-Clause "New" or "Revised" License
1.46k stars 781 forks source link

Pagination - Looping over subsequent results. #176

Closed louiswalch closed 9 years ago

louiswalch commented 9 years ago

I am trying to use the pagination feature to get more then 20 results from getTagMedia but hitting a wall. I have referred to wiki article (https://github.com/cosenary/Instagram-PHP-API/wiki/Using-Pagination) but getting error on the second loop of results.

Here is my code:

// Receive new data
$media = $instagram->getTagMedia($tag, 20);

do {

    if (!empty($media->data)) {
        // Just for testing, show username and posted date
        foreach ($media->data as $key => $data) {
            echo chr(10) . $key .') ' . $data->user->username . ' at ' . date('Y-m-d H:i:s', $data->caption->created_time);
        }        
    } else {
        // Some kind of error?
        var_dump($media);
    }

    // Don't forget this pagination method or this will become an infinite loop!
    $media = $instagram->pagination($media);

} while ($media);

And here is the error I get:

object(stdClass)#430 (1) {
  ["meta"]=>
  object(stdClass)#431 (3) {
    ["error_type"]=>
    string(25) "APIInvalidParametersError"
    ["code"]=>
    int(400)
    ["error_message"]=>
    string(31) "Count must be larger than zero."
  }
}
louiswalch commented 9 years ago

UPDATE

I discovered the solution, I was passing a limit as the second parameter to the pagination call.

I agree with what people are saying in #120 and #121, if the IG API requires something - your library also should.