skip to Main Content

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


  1. 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.

    $data =
    [
        'title' => 'Your title',
        'description' => 'Your description'
    ];
    
    $response = $fb->uploadVideo($pageId, $videoUrl, $data, $token);
    

    Note: the videoUrlmust be a relative path as the FacebookFile class uses functions like filesize.

    Login or Signup to reply.
  2. 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

    Login or Signup to reply.
  3. The truth is that you can’t mix photos and videos. Facebook’s API doesn’t allow that. You can make:

    • A post containing video + text (description)
    • A post containing multiple photos + text

    To make a video post you have to hit

    POST https://graph-video.facebook.com/v10.0/<page id>/videos?file_url=<public file URL>&access_token=<your access token>&published=true&description=<text>
    

    The file_url and description 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:

    POST https://graph.facebook.com/<page id>/photos?url=<public file URL>&access_token=<access token>&published=false
    

    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:

    POST https://graph.facebook.com/<page id>/feed?message=<text>&access_token=<access token>&attached_media[0]={"media_fbid":"<id>"}&attached_media[1]={"media_fbid":"<id>"}
    

    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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search