What are some best practices for verifying if a user has liked and shared a page on Facebook using PHP?
To verify if a user has liked and shared a page on Facebook using PHP, you can use the Facebook Graph API to check the user's likes and shares. You will need to get the user's access token and make API requests to retrieve the necessary information. Once you have the user's likes and shares data, you can check if the page you are interested in is among them.
// User access token
$user_access_token = 'USER_ACCESS_TOKEN';
// Page ID to check likes and shares
$page_id = 'PAGE_ID';
// API request to get user's likes
$user_likes = file_get_contents("https://graph.facebook.com/me/likes?access_token=$user_access_token");
// API request to get user's shared posts
$user_shared = file_get_contents("https://graph.facebook.com/me/sharedposts?access_token=$user_access_token");
// Check if the page ID is in the user's likes or shared posts
$liked = strpos($user_likes, $page_id) !== false;
$shared = strpos($user_shared, $page_id) !== false;
if ($liked && $shared) {
echo 'User has liked and shared the page.';
} elseif ($liked) {
echo 'User has liked the page but has not shared it.';
} elseif ($shared) {
echo 'User has shared the page but has not liked it.';
} else {
echo 'User has not liked or shared the page.';
}