What are the steps required to access Facebook likes using the Graph API in PHP?
To access Facebook likes using the Graph API in PHP, you need to authenticate your application with Facebook, obtain an access token, and then make a request to the Graph API endpoint for likes on a specific object (e.g., a post or a page). You can then parse the JSON response to extract the likes data.
<?php
$access_token = 'YOUR_ACCESS_TOKEN';
$object_id = 'YOUR_OBJECT_ID'; // e.g., a post ID or a page ID
$url = "https://graph.facebook.com/v13.0/{$object_id}/likes?access_token={$access_token}";
$response = file_get_contents($url);
$data = json_decode($response, true);
$likes_count = $data['summary']['total_count'];
echo "Total likes: " . $likes_count;
?>
Keywords
Related Questions
- What functions in PHP can be utilized to read and manipulate data from .txt files effectively?
- What are the advantages of using Json instead of URL-encoded data for AJAX requests in PHP?
- In what ways can PHP be integrated with MySQL to improve the handling of user-selected data updates, like moving images between tables?