Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/facebook/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 最近Facebook API的变化?_Javascript_Facebook_Facebook Graph Api - Fatal编程技术网

Javascript 最近Facebook API的变化?

Javascript 最近Facebook API的变化?,javascript,facebook,facebook-graph-api,Javascript,Facebook,Facebook Graph Api,当我尝试使用Facebook Javascript API迭代用户的“喜好”时,我遇到了一个新错误 现在我总共可以得到300个“喜欢”的结果(当限制为25个结果/页时,数据的价值为12页)。这是从今天开始的,上周我可以使用以下代码遍历我“喜欢”的所有页面: FB.api('me/likes', function(res) { iteratePages(res); }); res用一个包含25个我(用户)“喜欢”的页面的数组和一个包含“下一个”页面的分页属性进行响应,在解析出所有

当我尝试使用Facebook Javascript API迭代用户的“喜好”时,我遇到了一个新错误

现在我总共可以得到300个“喜欢”的结果(当限制为25个结果/页时,数据的价值为12页)。这是从今天开始的,上周我可以使用以下代码遍历我“喜欢”的所有页面:

 FB.api('me/likes', function(res) {
      iteratePages(res);
 });
res用一个包含25个我(用户)“喜欢”的页面的数组和一个包含“下一个”页面的分页属性进行响应,在解析出所有喜欢的页面后,我将导航到该页面。通常情况下,这种情况会一直持续到res.paging.next未定义,此时我将存储一些数据等等

我知道我有800多个喜欢的页面,但在API调用停止之前,我只得到了300个结果,并且出现了以下错误/堆栈跟踪:

TypeError: Cannot read property 'next' of undefined
at Object.iteratePages [as success] (http://mysitethatisstillinbeta.beta/js/dashboard.js:77:20)
at c (http://code.jquery.com/jquery-latest.min.js:4:26036)
at Object.p.fireWith [as resolveWith] (http://code.jquery.com/jquery-latest.min.js:4:26840)
at k (http://code.jquery.com/jquery-latest.min.js:6:14258)
at XMLHttpRequest.r (http://code.jquery.com/jquery-latest.min.js:6:18646)

有什么想法吗?这个问题让我很困惑,非常令人沮丧。

看起来页面属性在最后一项上已经不存在了,有几种解决方案

第一个也是最好的,将检测机制从检查response.paging.next是否存在切换到检查查询返回的数据长度:

if response.data.length > 0
    do whatever you're doing
    then call response.paging.after OR response.paging.next to turn the page
else
    you're at the end of your list
这就是响应包含数据时的样子:

{
  "data": [ ... 
],
"paging": {
  "cursors": {
    "after": "some cursor", 
    "before": "another cursor"
}, 
"previous": "some addr"
}}}
如果他们没有:

{ "data": [] }

可能有一个bug或更改限制了每个查询的页数,我认为这就是导致问题的原因增加返回结果的数量会抵消有限的页数(我从25页/页增加到1000页),希望其他人觉得这很有用

两天前我们有过一些类似的hikup,我想这只是Facebook的一个bug。希望他们能尽快解决这个问题。我相信他们改变了API,我将在下面回答我的问题。如果你想出了不同的解决方案,请告诉我。