简体   繁体   中英

Displaying user information from Instagram PHP API

Excuse the super-precise question but I'm fairly new at this and could use some help. I thought I was understanding everything until I hit this roadblock.

I'm using 9lesson's Instagram PHP Oauth tutorial , which is built upon cosenary's Instagram PHP API class.

Everything is running properly but I am trying to add a line which shows the logged-in user how many followers they have.

I added this third line, copying the first two lines which already existed.

echo '<b>Profile Pic:</b> '.$data->user->profile_picture.'</br>';
echo '<b>Access Token:</b> '.$data->access_token.'</br>';
echo '<b>Followed by</b> '.$data->user->counts->followed_by.'</br></div>';

I added the last line under $_SESSION['userdetails']=$data;

$followers =$data->user->counts->followed_by;

Why will this not return any data, even though it is the correct name for the endpoint? I feel like I've tried every possible combination of 10 things. Any help would be great!

I looked at the Instagram API youre using.

Looks like you're getting $data from this call

$data = $instagram->getOAuthToken($code);

This call is meant to get an access token and it calls this endpoint

https://api.instagram.com/oauth/access_token

if you look at the Instagram API you'll see that this call doesn't return any counts

{
    "access_token": "fb2e77d.47a0479900504cb3ab4a1f626d174d2d",
    "user": {
        "id": "1574083",
        "username": "snoopdogg",
        "full_name": "Snoop Dogg",
        "profile_picture": "http://distillery.s3.amazonaws.com/profiles/profile_1574083_75sq_1295469061.jpg"
    }
}

With his API im not sure how to get the count. I built an API (requires php 5.3+) that makes it super simple.

$current_user = $instagram->getCurrentUser();
$followers = $current_user->getFollowers(); //get first page of followers
$followers_count = $current_user->getFollowersCount(); //get number of followers

Here's an example

http://galengrover.com/projects/instagram/?example=current_user.php

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM