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!
If the account is private and you're unable to find it upon searching. Then, you can't really say that they have blocked you. However, if the account is public, and while searching for their page, you can't see any posts, their profile picture, followers count or the following count.
Instagram Feed is a place where you can share and connect with the people and things you care about. When you open Instagram or refresh your feed, the photos and videos we think you care about most will appear towards the top of your feed.
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.
I did 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/USER ID HERE/media/recent/?access_token=ACCES TOKEN HERE&count=14");
$result = json_decode($result);
foreach ($result->data as $post) {
if(empty($post->caption->text)) {
// Do Nothing
}
else {
echo '<a class="instagram-unit" target="blank" href="'.$post->link.'">
<img src="'.$post->images->low_resolution->url.'" alt="'.$post->caption->text.'" width="100%" height="auto" />
<div class="instagram-desc">'.htmlentities($post->caption->text).' | '.htmlentities(date("F j, Y, g:i a", $post->caption->created_time)).'</div></a>';
}
}
?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With