As of the 21st October 2019 Instagram prevented you from creating and managing your clients from within Instagram and everything is now managed through Facebook Developer, no real issue with that…
In my instance all that is required is to show a single user profile images. I got this working fairly quickly, however the Access Token just expires every 2 hours, then I need to re-authorise it again… This was never an issue before… You authorised once and it would just work.
Take this working code:
function fetchData($url){
$inst = curl_init($url);
curl_setopt($inst, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($inst, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($inst, CURLOPT_SSL_VERIFYPEER, 0);
$output = curl_exec($inst);
curl_close($inst);
return $output;
}
$insta_access_token = 'MY_ACCESS_TOKEN';
$insta_count = '6';
$instagram_result = fetchData("https://graph.instagram.com/me/media?fields=id,username,media_url&access_token={$insta_access_token}&count={$insta_count}");
$instagram_result = json_decode($instagram_result);
print_r($instagram_result);
This works fine until the access token expires.
I have seen other tricks around not using the API at all located here: How can I get a user's media from Instagram without authenticating as a user?
This uses PHP to extract profile contents and is the only viable solution from my research to display a basic image gallery from a single use profile:
$html = file_get_contents('https://instagram.com/apple/');
preg_match('/_sharedData = ({.*);</script>/', $html, $matches);
$profile_data = json_decode($matches[1])->entry_data->ProfilePage[0]->graphql->user;
Am I missing something or is there no way to keep a valid access token running once authenticated once for basic image display?
Cheers.
2
Answers
All what you need is to extend your access token duration by making a GET request to this endpoint (long lived access token is valuable for 60 days from what i know)
Hope this is what you were looking for =)