gpt4 book ai didi

javascript - Graph API 嵌套请求响应

转载 作者:行者123 更新时间:2023-11-27 23:22:33 25 4
gpt4 key购买 nike

我一整天都在努力寻找解决方案,但我找不到,所以你是我最后的希望!我使用 FB.api 进行嵌套请求,并得到了响应(已检查 console.log 并且响应正常)。问题是,当我尝试访问响应的数据时,我收到了未定义的错误,例如响应为空。功能。当我试图获得例如响应长度时,我什么也得不到。有任何想法吗?这是我从 console.log 收到的错误未捕获的类型错误:无法读取未定义的属性“长度”

FB.api(
'/me',
'GET',
{"fields":"likes.limit(100) {link,picture}"},
function(response) {
if (response == "undefined" || response == null || !response || response.error)
{
alert("error occured");
return;
}
console.log(response);
for (var l = response.data.length, i = 0; i < l; i++) {
}});

部分回复

 {
"likes": {
"data": [
{
"link": "https://www.facebook.com/G-Pappas-1881854208706899/",
"picture": {
"data": {
"is_silhouette": false,
"url": "https://scontent.xx.fbcdn.net/hprofile-xlp1/v/t1.0-1/p50x50/1909968_1936509979907988_8060180335068327040_n.jpg?oh=368e10a9ab58ad0f337647ec6187f204&oe=5723AD5D"
}
},
"id": "1881854208706899"
},
{
"link": "https://www.facebook.com/FOODMATES-112425739139239/",
"picture": {
"data": {
"is_silhouette": false,
"url": "https://scontent.xx.fbcdn.net/hprofile-xpt1/v/t1.0-1/p50x50/12565389_129926077389205_1734904915451564294_n.jpg?oh=e76b99b775f94a9291a8d3f97aaead06&oe=5727BF7C"
}
},
"id": "112425739139239"
},
{
"link": "https://www.facebook.com/ARKAS-The-Original-Page-352589524877216/",
"picture": {
"data": {
"is_silhouette": false,
"url": "https://scontent.xx.fbcdn.net/hprofile-xta1/v/t1.0-1/p50x50/1381313_352855468183955_671412865_n.jpg?oh=8bbdbfce5d0e34a1120ca9b3e3d1c22d&oe=576B0804"
}
},
"id": "352589524877216"
},

最佳答案

看起来您没有在响应中使用正确的点符号。

数据数组嵌套在 Likes 中。因此要访问您需要的数据:response.likes.data.length

所以要使用它,请尝试这样的操作:

  console.log(response);
for (var l = response.likes.data.length, i = 0; i < l; i++) {
response.likes.data[i]
}

编辑:这是一个 jsfiddle 链接,其中包含正确的点符号示例以及取出的信息:https://jsfiddle.net/b7r2qtre/

关于javascript - Graph API 嵌套请求响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35257452/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com