3

请原谅这个超精确的问题,但我对此很陌生,可以使用一些帮助。我以为我已经理解了一切,直到我遇到了这个障碍。

我正在使用9lesson 的 Instagram PHP Oauth 教程,它建立在 cosenary 的 Instagram PHP API 类之上。

一切运行正常,但我正在尝试添加一行,显示登录用户有多少关注者。

我添加了第三行,复制了已经存在的前两行。

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>';

我在下面添加了最后一行$_SESSION['userdetails']=$data;

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

为什么这不会返回任何数据,即使它是端点的正确名称?我觉得我已经尝试了 10 种可能的组合。任何帮助都会很棒!

4

1 回答 1

1

我查看了您正在使用的 Instagram API。

看起来你是$data从这个电话中收到的

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

此调用旨在获取访问令牌并调用此端点

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

如果您查看Instagram API,您会发现此调用不返回任何计数

{
    "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"
    }
}

使用他的 API,我不确定如何计算。我构建了一个API(需要 php 5.3+),使它变得超级简单。

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

这是一个例子

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

于 2013-02-06T03:46:06.977 回答