[英]Get image's URL from page's photos using Facebook Graph API (Javascript)
I have followed several tutorials but it seems the newest version of the Graph API broke many of them. 我遵循了一些教程,但是最新版本的Graph API似乎打破了许多教程。
Here's my code: 这是我的代码:
function getAlbumImages(){
FB.api(
'/760126260690750/photos',
'GET',
{"limit":"100",
"access_token":"833367813443301|nDhKBT0o6K7a7j_5LMfc3QSbRNs"},
function (response) {
if (response && !response.error) {
createGallery(response);
} else
console.log(response.error);
});
}
function createGallery(imageJSON) {
for (var i=0, length = imageJSON.data.length; i < length; i++){
var image = imageJSON.data[i];
$('body').append(image.name);
}
};
However, nothing is appended to the body. 但是,没有任何东西附加到身体上。 Upon further inspection of the API call, the method /albumid/photos returns a photo object as specified by the docs, but this object does not contain anything but the ID, title and date of the photo. 进一步检查API调用后,方法/ albumid / photos返回文档指定的照片对象,但是该对象除照片的ID,标题和日期外不包含其他任何内容。 This is an excerpt of the data returned by my query: 这是我的查询返回的数据的摘录:
{
"data": [
{
"created_time": "2015-07-23T21:39:40+0000",
"name": "summer is here!! #adisfrutar #relax #funnytime 💘😊🌴☀🐙🎼",
"id": "903479883022053"
},
So clearly, the new API call does not return the image URL as it used to. 显然,新的API调用不会返回图像URL。
My question is then, how do I get the image URLs from the page's album so I can display a gallery on my website? 我的问题是,如何从页面相册中获取图像URL,以便可以在我的网站上显示图库?
You need to add the image field to the url (fields=images). 您需要将图像字段添加到url(fields = images)。 Example: 例:
https://graph.facebook.com/v2.4/760126260690750/photos?access_token=833367813443301%7CnDhKBT0o6K7a7j_5LMfc3QSbRNs&fields=images,name,created_time https://graph.facebook.com/v2.4/760126260690750/photos?access_token=833367813443301%7CnDhKBT0o6K7a7j_5LMfc3QSbRNs&fields=images,name,created_time
EDIT: If you need additional information about the photo node, check the Graph Api: 编辑:如果您需要有关照片节点的其他信息,请检查Graph Api:
https://developers.facebook.com/docs/graph-api/reference/photo https://developers.facebook.com/docs/graph-api/reference/photo
You can see all possible parameters under the GET request. 您可以在GET请求下查看所有可能的参数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.