I'd like to get a user's Instagram feed using PHP. I've signed up for an Instagram Developer Account and tried pulling in a user's info and photos, but the response isn't stable. Sometimes I get a response and other times I keep getting the error: access_token is missing. Is there a solid example of getting a user's feed of photos by username?
Ideally, I'd like it to be as simple as:
$instagram = new Instagram();
$photos = $instagram->getPhotos("username-goes-here");
Where Instagram is a class that handles all the requests. Any help or direction is appreciated. Thanks!
Try this,
<?php
function fetchData($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
$result = fetchData("https://api.instagram.com/v1/users/ID-GOES-HERE/media/recent/?access_token=TOKEN-GOES-HERE");
$result = json_decode($result);
foreach ($result->data as $post) {
// Do something with this data.
}
?>
May this help you.