[英]I am trying to execute this facebook api but it is not working…can you suggest any corrections
function getalbum(){
FB.api(
'/me',
'GET',
{"fields":"albums{name,link}"},
function(response) {
var album=response.data[1]
document.getElementById("photo").innerHTML=album.link;
}
)};
每当我尝试打印相册链接时,它都会显示错误cannot read the property '1' of unknown
从facebook文档 :
因此,您的代码应为:
function getalbum(){
FB.api(
'/me',
'GET',
{"fields":"albums{name,link}"},
function(response) {
if (response.error) {
console.log(error);
} else {
if (response.albums.length > 0) {
var album=response.albums[0]
document.getElementById("photo").innerHTML=album.link;
}
}
}
)};
请注意,您的albums
属性可直接在response
对象上访问。
仅在对结果分页时才需要使用响应对象的data
,如文档中所述
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.