I try to publish a post with multiple videos and photos by using the PHP SDK. I uploaded videos and photos using batch request and got the id. Then I pass the media ids along with post data using attached_media. Things work fine for single or multiple photos. But not for a single video or multiple videos. I got this error: “Graph returned an error: (#10) Application does not have permission for this action” whenever ids of videos are included in attached_media.
Here is the code that I used:
$fb = $this->init(); try{ // Returns a FacebookFacebookResponse object
$publishData = [ 'message' => $post['content']];
if(count($media_ids) > 0){
$publishData ['attached_media'] = [];
foreach($media_ids as $key => $media_id){
array_push($publishData['attached_media'],'{"media_fbid":"' . $media_id . '"}');
}
}
$response = $fb->post(
'/me/feed',$publishData
,
$accessToken
);
}
catch(FacebookResponseException $e){
echo 'Graph returned an error: ' . $e->getMessage();
echo $e->getTraceAsString();
exit;
}
catch(FacebookSDKException $e){
echo 'Facebook SDK returned an error: ' . $e->getMessage();
echo $e->getTraceAsString();
exit;
}
$graphNode = $response->getGraphNode();
Is there anyway to solve this. Thank you.
3
Answers
I know its been a while but I was having the same problem and it’s 2020…
The only way I was able to show the video in the timeline of a page was using the following Facebook documentation that covers uploading & posting a video to a user’s timeline with the Facebook SDK for PHP.
https://developers.facebook.com/docs/php/howto/example_upload_video
It’s clearly not the best approach but at least the video appears in the timeline with some title and description.
Note: the
videoUrl
must be a relative path as the FacebookFile class uses functions likefilesize
.Facebook doesn’t directly allow to publish post with multiple videos and photos on the business page. However, it is possible on a personal page so as an alternate solution you can create a post on a personal page and share it on the business page.
Check this video for more information: https://www.youtube.com/watch?v=AoK_1S71q1o
The truth is that you can’t mix photos and videos. Facebook’s API doesn’t allow that. You can make:
To make a video post you have to hit
The
file_url
anddescription
should be URL encoded.To post multiple photos you first do the photo "uploading" and as a result you’ll have ids. Those ids you set to
attached_media
param.Getting photo ids:
Notice the
published=false
. That’s important. Without that you’ll make a page post containing a single photo.And finally making the actual page post:
P.S.
This approach assumes that you have your content uploaded somewhere else and you have public URLs where this content is available. If you have the raw files and you want to upload them to Facebook then you have to follow another approach.