skip to Main Content

I have a Facebook page where i have 3 posts and those posts contains videos in it but when i try to access videos using graph api, No videos are getting returned.

here is the API I’m trying

API - https://graph-video.facebook.com/{ page_id }/videos?access_token={ access_token }

here are the permissions given to this access_token

email
pages_show_list
pages_read_engagement
public_profile

Then i tried following approach whether videos are available or not just for R&D purpose and i am getting the videos detail

  • Get all posts via access token
  • From the posts response get page access token
  • use the page access token use attachment api
  • Here i am getting the video details

So, the query is why /videos api not giving me any result. Can anyone please help me out on this ?

Thanks.

2

Answers


  1. This is how I’d request to get videos from facebook page, send out a GET request to /{page-id}/videos using curl like below.

    curl -i -X GET "https://graph.facebook.com/{page-id}/videos?access_token={access-token}"

    Login or Signup to reply.
  2. Check Permissions:

    pages_read_engagement
    pages_read_user_content
    pages_show_list 
    

    Use the Correct Endpoint:

       https://graph.facebook.com/{page_id}/videos?access_token={access_token}
    

    Check Page Roles:

    <?php
    $page_id = 'your_page_id';
    $access_token = 'your_access_token';
    
    $url = "https://graph.facebook.com/{$page_id}/videos?access_token={$access_token}";
    
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    
    $response = curl_exec($ch);
    if (curl_errno($ch)) {
        echo 'Error:' . curl_error($ch);
    } else {
        $data = json_decode($response, true);
        print_r($data);
    }
    curl_close($ch);
    ?>
    

    If the /videos endpoint still does not return any results, try fetching posts and then extracting video details from the posts:

    <?php
    $page_id = 'your_page_id';
    $access_token = 'your_access_token';
    
    $url = "https://graph.facebook.com/{$page_id}/posts?access_token={$access_token}";
    
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    
    $response = curl_exec($ch);
    if (curl_errno($ch)) {
        echo 'Error:' . curl_error($ch);
    } else {
        $posts = json_decode($response, true);
        foreach ($posts['data'] as $post) {
            $post_id = $post['id'];
            $attachment_url = "https://graph.facebook.com/{$post_id}/attachments?access_token={$access_token}";
            
            $ch_attachment = curl_init();
            curl_setopt($ch_attachment, CURLOPT_URL, $attachment_url);
            curl_setopt($ch_attachment, CURLOPT_RETURNTRANSFER, true);
            
            $attachment_response = curl_exec($ch_attachment);
            if (curl_errno($ch_attachment)) {
                echo 'Error:' . curl_error($ch_attachment);
            } else {
                $attachments = json_decode($attachment_response, true);
                print_r($attachments);
            }
            curl_close($ch_attachment);
        }
    }
    curl_close($ch);
    ?>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search