Instagram API: How to get all user media?

后端 未结 10 2082
灰色年华
灰色年华 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条回答
  •  Happy的楠姐
    2020-11-28 03:10

    What I had to do is (in Javascript) is go through all pages by using a recursive function. It's dangerouse as instagram users could have thousands of pictures i a part from that (so your have to controle it) I use this code: (count parameter I think , doesn't do much)

            instagramLoadDashboard = function(hash)
        {
            code = hash.split('=')[1];
    
            $('#instagram-pictures .images-list .container').html('').addClass('loading');
    
    
            ts = Math.round((new Date()).getTime() / 1000);
            url = 'https://api.instagram.com/v1/users/self/media/recent?count=200&min_timestamp=0&max_timestamp='+ts+'&access_token='+code;
    
            instagramLoadMediaPage(url, function(){
    
                galleryHTML = instagramLoadGallery(instagramData);
                //console.log(galleryHTML);
                $('#instagram-pictures .images-list .container').html(galleryHTML).removeClass('loading');
                initImages('#instagram-pictures');
    
                IGStatus = 'loaded';
    
            });
    
        };
    
        instagramLoadMediaPage = function (url, callback)
        {
            $.ajax({
                    url : url,
                    dataType : 'jsonp',
                    cache : false,
                    success:  function(response){
    
                                            console.log(response);
    
                                            if(response.code == '400')
                                            {
                                                alert(response.error_message);
                                                return false;
                                            }
    
                                            if(response.pagination.next_url !== undefined) {
                                                instagramData = instagramData.concat(response.data);
                                                return instagramLoadMediaPage(response.pagination.next_url,callback);
                                            }
    
                                            instagramData = instagramData.concat(response.data);
                                            callback.apply();
                                        }
            });
        };
    
        instagramLoadGallery = function(images)
        {
            galleryHTML ='
      '; for(var i=0;i'; } galleryHTML +='
    '; return galleryHTML; };

    There some stuff related to print out a gallery of picture.

提交回复
热议问题