Facebook Graph API 发布 post 多个附件
Facebook Graph API publish post with multiple attachments
我正在尝试使用图表 API 将 post 发布到 Facebook 新闻提要(时间线)。
我可以使用 Facebook 标准 GUI Messenger 发布 post 并向其中添加照片 post。但是如何从 Facebook Graph API?
我可以将图片上传到相册并尝试在这些图片上创建 link。但是只能创建1个link.
发布 post 添加了超过 1 张图片到此 post 的正确算法是什么?
目前无法发布一张 post 多张图片。您需要为每个图像创建单独的 post,或者使用您最喜欢的服务器语言将所有图像放在一个图像中,然后 post 作为单张图像。
实际上你可以上传多故事照片(我使用 Graph Api 和 PHP 做到了)但是如果你需要安排这个问题就来了 post.Your post是时间表,但也会显示在页面的 Feed 上。
P.S。我正在使用 Graph Api v2.9
PHP代码
$endpoint = "/".$page_id."/photos";
foreach ($multiple_photos as $file_url):
array_push($photos, $fb->request('POST',$endpoint,['url' =>$file_url,'published' => FALSE,]));
endforeach;
$uploaded_photos = $fb->sendBatchRequest($photos, $page_access_token);
foreach ($uploaded_photos as $photo):
array_push($data_post['attached_media'], '{"media_fbid":"'.$photo->getDecodedBody()['id'].'"}');
endforeach;
$data_post['message'] = $linkData['caption'];
$data_post['published'] = FALSE;
$data_post['scheduled_publish_time'] = $scheduled_publish_time;
$response = $fb->sendRequest('POST', "/".$page_id."/feed", $data_post, $page_access_token);
$post_id = $cresponse->getGraphNode()['id'];
根据文档,可以这样做:https://developers.facebook.com/docs/graph-api/photo-uploads#publishing-a-multi-photo-story
要点是:
- 上传照片但将它们标记为 "unpublished",保留 ID
- 创建 "post" 并将 "unpublihsed" 张照片作为附件
希望对您有所帮助。
我正在尝试使用图表 API 将 post 发布到 Facebook 新闻提要(时间线)。
我可以使用 Facebook 标准 GUI Messenger 发布 post 并向其中添加照片 post。但是如何从 Facebook Graph API?
我可以将图片上传到相册并尝试在这些图片上创建 link。但是只能创建1个link.
发布 post 添加了超过 1 张图片到此 post 的正确算法是什么?
目前无法发布一张 post 多张图片。您需要为每个图像创建单独的 post,或者使用您最喜欢的服务器语言将所有图像放在一个图像中,然后 post 作为单张图像。
实际上你可以上传多故事照片(我使用 Graph Api 和 PHP 做到了)但是如果你需要安排这个问题就来了 post.Your post是时间表,但也会显示在页面的 Feed 上。
P.S。我正在使用 Graph Api v2.9
PHP代码
$endpoint = "/".$page_id."/photos";
foreach ($multiple_photos as $file_url):
array_push($photos, $fb->request('POST',$endpoint,['url' =>$file_url,'published' => FALSE,]));
endforeach;
$uploaded_photos = $fb->sendBatchRequest($photos, $page_access_token);
foreach ($uploaded_photos as $photo):
array_push($data_post['attached_media'], '{"media_fbid":"'.$photo->getDecodedBody()['id'].'"}');
endforeach;
$data_post['message'] = $linkData['caption'];
$data_post['published'] = FALSE;
$data_post['scheduled_publish_time'] = $scheduled_publish_time;
$response = $fb->sendRequest('POST', "/".$page_id."/feed", $data_post, $page_access_token);
$post_id = $cresponse->getGraphNode()['id'];
根据文档,可以这样做:https://developers.facebook.com/docs/graph-api/photo-uploads#publishing-a-multi-photo-story
要点是:
- 上传照片但将它们标记为 "unpublished",保留 ID
- 创建 "post" 并将 "unpublihsed" 张照片作为附件
希望对您有所帮助。