What is the recommended method to display a Facebook Fanpage profile picture on a webpage using PHP?
To display a Facebook Fanpage profile picture on a webpage using PHP, you can use the Facebook Graph API to fetch the profile picture URL and then display it on your webpage using an HTML <img> tag.
<?php
$fanpage_id = 'YOUR_FANPAGE_ID';
$access_token = 'YOUR_ACCESS_TOKEN';
$response = file_get_contents("https://graph.facebook.com/{$fanpage_id}?fields=picture&access_token={$access_token}");
$data = json_decode($response);
$profile_picture_url = $data->picture->data->url;
echo '<img src="' . $profile_picture_url . '" alt="Fanpage Profile Picture">';
?>
Keywords
Related Questions
- What best practices should be followed when handling form submissions and data validation in PHP scripts to avoid errors and ensure proper functionality?
- What are the potential pitfalls of using the str_contains function in PHP for spam protection?
- How can the array_multisort function be used effectively in PHP to sort arrays in descending order?