gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-10-31 21:38:02 25 4
gpt4 key购买 nike

请原谅这个 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com