我尝试在Facebook上创建包含多张照片和视频的帖子。我是这样做的:
使用参数attached_media
创建帖子
$fb = new \Facebook\Facebook([
'app_id' => '...',
'app_secret' => '...',
'default_graph_version' => 'v3.2',
]);
// photos
$fbPhotos = [];
foreach ($images as $image) {
$response = $fb->post(
"/$pageId/photos",
['url' => $image, 'published' => false],
$accessToken
);
$graphNode = $response->getGraphNode();
$fbPhotos[] = $graphNode['id'];
}
// videos
foreach ($videos as $video) {
$response = $fb->uploadVideo(
"/$pageId/videos",
$video,
['title' => 'title', 'description' => 'description', 'published' => false],
$accessToken
);
$fbVideos[] = $response['video_id'];
}
// post
$response = $fb->post(
"/$pageId/feed",
[
'message' => $message,
'published' => true,
'attached_media' => json_encode(array_map(
function($v) { return ['media_fbid' => $v]; },
array_merge($fbPhotos, $fbVideos)
)),
],
$accessToken
);
对于上一个请求,我收到错误OAuth "Facebook Platform" "invalid_request" "(#10) Application does not have permission for this action
。如果我在$fbVideos
帖子中发送的最后一封没有attached_media
的请求成功创建了多张照片。
是否可以用多张照片和视频创建同一条帖子?有什么想法吗?