php - 显示来自 Instagram PHP API 的用户信息

标签 php api oauth instagram

请原谅这个 super 精确的问题,但我在这方面还很陌生,需要一些帮助。在我遇到这个障碍之前,我以为我已经理解了一切。

我正在使用 9lesson's Instagram PHP Oauth tutorial ,它建立在 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 种可能的组合。任何帮助都会很棒!

最佳答案

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

看起来你正在从这个调用中获取 $data

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

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

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+)使其 super 简单。

$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

关于php - 显示来自 Instagram PHP API 的用户信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14542691/

相关文章:

受 url 传播变化启发的 PHP 和服务器层次结构设计

c# - PayPal Rest API - 使用更新的交易信息执行付款

javascript - Instagram.com/username/media 不再有效

android - 将原生 Google 帐户选择器与 B2C 结合使用

android - 请求服务器授权码时,GoogleSignInResult 在 Android 应用程序中返回 DEVELOPER_ERROR

php - PHP中is_null "== NULL"和 "=== NULL"的区别

php - mysql插入处理很多值

authentication - RestSharp 中的 OAuth 2.0 身份验证

javascript - rev slider javascript 出现在 WordPress 搜索结果中

java - 使用 GSON 在 Java 中组织输出 JSON 响应