facebook reels video views count in api in php

 To retrieve the Facebook Reels video views count using the Facebook API in PHP, you can use the following code:


<?php // Replace with your Facebook app ID, app secret, and access token $appId = 'YOUR_APP_ID'; $appSecret = 'YOUR_APP_SECRET'; $accessToken = 'YOUR_ACCESS_TOKEN'; // Replace with the ID of the Reels video you want to retrieve the views count for $reelsVideoId = 'YOUR_REELS_VIDEO_ID'; // Make a GET request to the Facebook API $requestUrl = "https://graph.facebook.com/v13.0/$reelsVideoId/insights/video_views"; $requestUrl .= "?access_token=$accessToken"; $response = file_get_contents($requestUrl); // Decode the JSON response $data = json_decode($response, true); // Extract the total video views count from the latest data point $viewsCount = $data['data'][0]['values'][0]['value']; echo "Total Reels video views count: $viewsCount"; ?>




This code sends a GET request to the Facebook API with the Reels video ID and access token. It then extracts the total video views count from the latest data point in the response and outputs it to the user.

Note that this code uses the file_get_contents() function to make the API request, which requires the allow_url_fopen setting to be enabled in your PHP configuration. Alternatively, you can use a library like cURL or Guzzle to make the API request.


Post a Comment

أحدث أقدم