$url = 'https://api.instagram.com/v1/users/XXXX?access_token=XXXX';
echo json_decode(file_get_contents($url))->{'followed_by'};
I am using this code and I do not understand what the issue is. I'm new to PHP so excuse the newbie mistake. I'm trying to get the "followed_by" to display on its own. I've managed to get Facebook's "like" and twitter's followers to display this way.
Tap in the top right, then tap Your activity. Tap Download your information. Enter the email address where you'd like to receive a link to your data, then tap Request Download. Enter your Instagram account password and tap Next in the top right, then tap Done.
The API can be used to get and publish their media, manage and reply to comments on their media, identify media where they have been @mentioned by other Instagram users, find hashtagged media, and get basic metadata and metrics about other Instagram Businesses and Creators.
In case you need to grab follower count (or other fields) without logging in, Instagram is nice enough to put them in JSON inside the page source:
$raw = file_get_contents('https://www.instagram.com/USERNAME'); //replace with user
preg_match('/\"edge_followed_by\"\:\s?\{\"count\"\:\s?([0-9]+)/',$raw,$m);
print intval($m[1]);
//returns "123"
Hope that helps.
24 May 2016 Updated to be more tolerant of spaces in JSON.
19 Apr 2018 Updated to use new "edge_" prefix.
According to the Instagram API Docs, followed_by
is a child of counts
which is a child of data
.
https://api.instagram.com/v1/users/1574083/?access_token=ACCESS-TOKEN
Returns:
{
"data": {
"id": "1574083",
"username": "snoopdogg",
"full_name": "Snoop Dogg",
"profile_picture": "http://distillery.s3.amazonaws.com/profiles/profile_1574083_75sq_1295469061.jpg",
"bio": "This is my bio",
"website": "http://snoopdogg.com",
"counts": {
"media": 1320,
"follows": 420,
"followed_by": 3410
}
}
The following should therefore work.
<?php
$url = 'https://api.instagram.com/v1/users/XXXX?access_token=XXXX';
$api_response = file_get_contents($url);
$record = json_decode($api_response);
echo $record->data->counts->followed_by;
// if nothing is echoed try
echo '<pre>' . print_r($api_response, true) . '</pre>';
echo '<pre>' . print_r($record, true) . '</pre>';
// to see what is in the $api_response and $record object
Try this..
<?php
$instagram = "https://api.instagram.com/v1/users/xxxxx/?access_token=xxxxx";
$instagram_follows = json_decode(file_get_contents($instagram))->data->counts->followed_by;
echo $instagram_follows;
?>
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