How do I use Instagram's API to display a gallery of my own photos?

送分小仙女□ 提交于 2019-12-31 09:44:50

问题


I'd like to use Instagram's API to display a gallery of just my own photos on a webpage. Is this possible?


回答1:


Take a look here: http://instagram.com/developer/endpoints/users/

Most of the endpoints require users to be authenticated. You can retrieve tagged pictures and popular pictures without authentication. In order to display your own, you would need a user to be logged in with Instagram.

EDIT: Check this out: http://www.blueprintinteractive.com/blog/how-instagram-api-fancybox-simplified




回答2:


Method 1 - Use Instagram API

No you don't always need the Access Token. You can also use the Client ID like in this API request - https://api.instagram.com/v1/tags/nofilter/media/recent?client_id=CLIENT-ID

User Photos Endpoint -
https://api.instagram.com/v1/users/{user-id}/media/recent/?client_id=CLIENT-ID

You will need to replace your User ID in the above URL. The output will be a JSON response so you will have to display the photos yourself.

Method 2 - Use a Plugin

You can directly use a plugin that will embed your Photos from your Instagram Account onto your website. A good Example would be - InstaMax plugin which will display all your photos, videos with likes and comments.

A small Demo of the plugin is present here - http://demos.codehandling.com/instamax_demo/instamax_live_edit.html

Update 2016

Method 1 will not work after June 2016 due to changes in Instagram API. You need to have you app approved from Instagram and then generate an Access Token.

  1. Generating the Token is the easy part. You can simple use the below API from your browser -

    https://api.instagram.com/oauth/authorize/?client_id=CLIENT-ID&redirect_uri=REDIRECT-URI&response_type=token

  2. Frankly, the hardest part is getting your APP approved from Instagram. It took me a month and several rejections to understand what their platform policies are and how to send the request for approval.

I would recommend you to use a plugin that already has an approved App so that you can use their App to generate Tokens for their plugin. This is why I created my free InstaMax plugin.




回答3:


Use jQuery latest version from CDN and then:

 $(document).ready(function{
    var token = 'Your Access Token', 
        userid = 'Your User ID',
        num_photos = 10; // how much photos you want to get

    $.ajax({
        url: 'https://api.instagram.com/v1/users/' + userid + '/media/recent',
        dataType: 'jsonp',
        type: 'GET',
        data: {access_token: token, count: num_photos},
        success: function(data){
            console.log(data);
            for( n in data.data ){                  
                $('body').append('<div><img src="'+data.data[n].images.standard_resolution.url+'"></div>');
            }
        },
        error: function(data){
            console.log(data);
        }
    });
})

DEMO



来源:https://stackoverflow.com/questions/12478772/how-do-i-use-instagrams-api-to-display-a-gallery-of-my-own-photos

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!