2017-02-13 67 views
0

我正在与Instagram的图像画廊,现在我想链接我的画廊,我想当用户点击图像,它假设重定向他的Instagram帖子。所以现在我需要从Instagram API获得链接。 现在我只有图片和我得到它以这种方式:Instagram的api返回文章链接

jQuery.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){ ........ 

所以有人可以帮我怎么去交的网址吗?

+0

您是否在寻找图片或帖子的网址? –

+0

@TariqB。帖子的网址。 Sry我的错误 –

+0

数据对象中的链接参数应该是该帖子的URL。请尝试。 –

回答

0

Instagram API,您应该使用链接参数来获取每张照片的链接。这个代码应该在里面成功(数据)函数。使用/用户/自/媒体/最近端点将大概叫这样的:

[...] 
success: function(data){ 
    for (i = 0; i < data.length; i++){ 
     var photoURL = data[i].images.standard_resolution.url; 
     var photoLink = data[i].link; 
     var username = data[i].user.username; 

     var html = "<a href='" + photoLink + "' target='_blank'>"; 
     html += " <img src='" + photoURL + "' alt='" + username + "'>"; 
     html += "</a>"; 

     // here you should append this html code to some container box 
     document.getElementById("myContainer").innerHTML += html; 
    } 
} 

这上面的代码并没有进行测试。但我相信它工作正常。 以下是media object returned by Instagram,所以你可以选择你需要的任何信息。我隐藏了users_in_photo和images部分以便于理解。

{ 
"data": { 
    "type": "image", 
    "users_in_photo": [{...}], 
    "filter": "Walden", 
    "tags": [], 
    "comments": { "count": 2 }, 
    "caption": null, 
    "likes": { "count": 1 }, 
    "link": "http://instagr.am/p/D/", 
    "user": { 
     "username": "kevin", 
     "full_name": "Kevin S", 
     "profile_picture": "...", 
     "id": "3" 
    }, 
    "created_time": "1279340983", 
    "images": {...}, 
    "id": "3", 
    "location": null 
} 
} 

用户在照片部分:

"users_in_photo": [{ 
     "user": { 
      "username": "kevin", 
      "full_name": "Kevin S", 
      "id": "3", 
      "profile_picture": "..." 
     }, 
     "position": { 
      "x": 0.315, 
      "y": 0.9111 
     } 
    }], 

图片部分:

"images": { 
     "low_resolution": { 
      "url": "http://distillery.s3.amazonaws.com/media/2010/07/16/4de37e03aa4b4372843a7eb33fa41cad_6.jpg", 
      "width": 306, 
      "height": 306 
     }, 
     "thumbnail": { 
      "url": "http://distillery.s3.amazonaws.com/media/2010/07/16/4de37e03aa4b4372843a7eb33fa41cad_5.jpg", 
      "width": 150, 
      "height": 150 
     }, 
     "standard_resolution": { 
      "url": "http://distillery.s3.amazonaws.com/media/2010/07/16/4de37e03aa4b4372843a7eb33fa41cad_7.jpg", 
      "width": 612, 
      "height": 612 
     } 
    }, 

祝你好运!