Instagram API: How to get all user media?

后端 未结 10 2046
灰色年华
灰色年华 2020-11-28 02:36

In general I need to get all user media.

User has more than 250 photos.

I do /users/1/media/recent/?access_token=...&count=250

But i

相关标签:
10条回答
  • 2020-11-28 02:53

    I've solved this issue with the optional parameter count set to -1.

    0 讨论(0)
  • 2020-11-28 02:55

    It was a problem in Instagram Developer Console. max_id and min_id doesn't work there.

    0 讨论(0)
  • 2020-11-28 02:56

    See http://instagram.com/developer/endpoints/ for information on pagination. You need to subsequentially step through the result pages, each time requesting the next part with the next_url that the result specifies in the pagination object.

    0 讨论(0)
  • You can user pagination of Instagram PHP API: https://github.com/cosenary/Instagram-PHP-API/wiki/Using-Pagination

    Something like that:

        $Instagram = new MetzWeb\Instagram\Instagram(array(
            "apiKey"      => IG_APP_KEY,
            "apiSecret"   => IG_APP_SECRET,
            "apiCallback" => IG_APP_CALLBACK
        ));
        $Instagram->setSignedHeader(true);
    
        $pictures = $Instagram->getUserMedia(123);
        do {
    
            foreach ($pictures->data as $picture_data):
    
                echo '<img src="'.$picture_data->images->low_resolution->url.'">';
    
            endforeach;
    
        } while ($pictures = $instagram->pagination($pictures));
    
    0 讨论(0)
  • 2020-11-28 02:59

    Use the best recursion function for getting all posts of users.

    <?php
        set_time_limit(0);
        function getPost($url,$i) 
        {
            static $posts=array();  
            $json=file_get_contents($url);
            $data = json_decode($json);
            $ins_links=array();
            $page=$data->pagination;
            $pagearray=json_decode(json_encode($page),true);
            $pagecount=count($pagearray);
    
            foreach( $data->data as $user_data )
            {
                $posts[$i++]=$user_data->link;
            }
    
            if($pagecount>0)
                return getPost($page->next_url,$i);
            else
                return $posts;
        }
        $posts=getPost("https://api.instagram.com/v1/users/CLIENT-ACCOUNT-NUMBER/media/recent?client_id=CLIENT-ID&count=33",0);
    
        print_r($posts);
    
    ?>
    
    0 讨论(0)
  • 2020-11-28 03:02

    Use the next_url object to get the next 20 images.

    In the JSON response there is an pagination array:

     "pagination":{
          "next_max_tag_id":"1411892342253728",
          "deprecation_warning":"next_max_id and min_id are deprecated for this endpoint; use min_tag_id and max_tag_id instead",
          "next_max_id":"1411892342253728",
          "next_min_id":"1414849145899763",
          "min_tag_id":"1414849145899763",
          "next_url":"https:\/\/api.instagram.com\/v1\/tags\/lemonbarclub\/media\/recent?client_id=xxxxxxxxxxxxxxxxxx\u0026max_tag_id=1411892342253728"
     }
    

    This is the information on specific API call and the object next_url shows the URL to get the next 20 pictures so just take that URL and call it for the next 20 pictures.

    For more information about the Instagram API check out this blogpost: Getting Friendly With Instagram’s API

    0 讨论(0)
提交回复
热议问题