Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
841 views
in Technique[技术] by (71.8m points)

jquery - Display Instagram photos from different account to my webpage

I am looking for the way to display not my instagram photos to my website page, but can't. Is it possible to do if i have just an account name of the instagram user (e.g. jamieoliver). My website is written on Wordpress.

Need to display not my images

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This URL format http://instagram.com/{instagram user name}/media will return a json file with the latest (20+/-) media files from that user.

In the example of jamieoliver you can do http://instagram.com/jamieoliver/media

You could process that json response through an (jQuery) ajax call like :

$.ajax({
    url: "http://instagram.com/jamieoliver/media",
    dataType : "jsonp", // this is important
    cache: false,
    success: function(response){
        // process the json response to get images
        // e.g. the first image should be something like : 
        // response.items.images[0].low_resolution
        // you could call an external function to iterate through the response
    }
});

Of course, I assume you understand what a json format looks like. If you are using WordPress, maybe you could find a plugin to deal with that json response


EDIT:

It seems like the response from http://instagram.com/{author_name}/media is not jsonp but json (see this for further reference), however setting a json dataType will return a cross-domain error.

The workaround is to use whateverorigin.org third-party app to circumvent the same-origin policy.

So format your URL like

"http://whateverorigin.org/get?url=" + encodeURIComponent("http://instagram.com/{author_name}/media");

The whateverorigin server will act as proxy and return the proper json format.

Note that you still need to use dataType : "jsonp" in your ajax call.

See JSFIDDLE


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...