Problems with the Instagram API?

0

Hello. I need to get several Instagram post and for this I did a simple classes using CURL to get the Json from Instagram. For this I used a token and a normal userid. When the first request is made within the while block, it returns the json with the most recent post and within that json a property called next_url which in theory is a pagination for the next recent post. Well by running the code below he can get this to next_url a few times until he gets to the last one, but he does this by skipping several more recent dates. So think of days 11/03/15 had the last post, in the second run it goes to 2/27/15, the third to 09/02/15 and the fourth to 02/12/14. What can it be? logic error, or problems with the API.

    while ($api != false) {
            if ($count == $limite) {
                break;
            }
            $response = json_decode($this->getUrl($api));
            $this->posts[$this->post_count] = array("type" => "it");
            $this->posts[$this->post_count]["imgcont"] = "yes";
            $this->posts[$this->post_count]["imagem"] = $response->data[0]->images->standard_resolution->url;
            $this->posts[$this->post_count]["texto"] = isset($response->data[0]->caption->text) ? $response->data[0]->caption->text : '';
            $this->posts[$this->post_count]["postdate"] = $this->dateToString($this->stampToDate($response->data[0]->created_time));
            $this->posts[$this->post_count]["elapsed"] = $this->getDays($response->data[0]->created_time, false);
            $this->posts[$this->post_count]["link"] = $response->data[0]->link;
            $this->post_count++;
            $count++;
            $api = false;
            if (property_exists($response, "pagination")) {
                if (property_exists($response->pagination, "next_url")) {
                    $api = $response->pagination->next_url;
                }
            }
        }
    
asked by anonymous 12.03.2015 / 20:58

1 answer

1

There is a logic error. You are only getting the first post from each page. The data attribute of json is an array , it is sure to iterate over it before making a new request for the next page.

    
19.11.2015 / 20:35