Are there any best practices or alternative methods for retrieving and displaying Instagram account information in PHP?

To retrieve and display Instagram account information in PHP, one common method is to use the Instagram API. However, since Instagram deprecated its API in 2020, an alternative approach is to use the Instagram Basic Display API, which requires creating a Facebook app and obtaining an access token. This access token can then be used to make API requests to retrieve account information such as profile details, posts, and media.

<?php

$accessToken = 'YOUR_ACCESS_TOKEN';
$userId = 'YOUR_INSTAGRAM_USER_ID';

$url = "https://graph.instagram.com/{$userId}?fields=id,username,media_count&access_token={$accessToken}";

$response = file_get_contents($url);
$data = json_decode($response, true);

if(isset($data['username'])) {
    echo "Username: " . $data['username'] . "<br>";
    echo "Media Count: " . $data['media_count'] . "<br>";
} else {
    echo "Error retrieving account information.";
}

?>