gpt4 book ai didi

Facebook 批量请求

转载 作者:行者123 更新时间:2023-11-30 05:28:41 26 4
gpt4 key购买 nike

我正在尝试将几个请求重写为一个批处理请求

$posts = $facebook->api('/me/feed?limit=9999999');

for($i = 0; $i < count($posts['data']); $i++)
{

$comments = $facebook->api($posts['data'][$i]['id'].'/comments');
$likes = $facebook->api($posts['data'][$i]['id'].'/likes');

}

进入

$batch = array();

$req = array(
'method' => 'GET',
"name" => "prispevky",
'relative_url' => '/me/feed',
);

$batch[] = json_encode($req);


$req = array(
'method' => 'GET',
'relative_url' => '{result=prispevky:$.data.*.from.id}/comments'
);

$batch[] = json_encode($req);

$req = array(
'method' => 'GET',
'relative_url' => '{result=prispevky:$.data.*.id}/likes'
);

$batch[] = json_encode($req);

$params = array(
'batch' => '[' . implode(',',$batch) . ']'
);

try
{
$info = $facebook->api('/','POST',$params);
print_r($info);
}
catch(FacebookApiException $e) {
error_log($e);
$info = null;
}

但我收到错误 404,您请求的某些别名不存在,然后在墙上列出了所有 Feed 的 ID。当我通过简单的请求只调用一个时,我会成功收到它。有人可以帮助我并告诉我哪里有错误吗?

最佳答案

Henry 试试循环到 $Comments & $Likes
“这将从帖子数据 0 返回评论和点赞。对于超出此范围的每个帖子,你都必须添加一个新数组。我看到你是如何尝试循环数组请求的,我从来没有能够让那个方法工作,因为可以说,评论和点赞存在于单独的表格中。”

注意:批处理最多只接受 20 个请求,因此如果第一个请求是帖子,则请求循环 999999 个帖子仍然只会返回前 19 组评论/喜欢。


$queryProfileFeed = array(
array('method' => 'GET', 'relative_url' => '/me/feed?fields=id%26'.$app_access_token.'' 'name' => 'getLnC', 'omit_response_on_success' => false),
array('method' => 'GET', 'relative_url' => '/{result=getLnC:$.data.0.id}/comments?fields=id%26offset=0'),
array('method' => 'GET', 'relative_url' => '/{result=getLnC:$.data.0.id}/likes?fields=id%26offset=0'),
);
$batchResponse = $facebook->api('?batch='.json_encode($queryProfileFeed), 'POST');
/* json decode response for comments */
$Comments = json_decode($batchResponse[1]['body'], true);
/* json decode response for likes */
$Likes = json_decode($batchResponse[2]['body'], true);

我使用上述方法,但有更多批处理请求以在我的插件中显示我的墙

但我只要求前 10 个帖子中的前 2 个评论和点赞。不止于此似乎会降低性能并且经常超时抛出“别名不存在”之类的错误

关于Facebook 批量请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7970632/

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