從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
}
},
祝你好運!
您是否在尋找圖片或帖子的網址? –
@TariqB。帖子的網址。 Sry我的錯誤 –
數據對象中的鏈接參數應該是該帖子的URL。請嘗試。 –