在私有profil上请求媒体时获取"APINotAllowedError",即使允许所有范围也是如此

Dan*_*tag 3 php api instagram

我正在使用PHP Instagram API https://github.com/cosenary/Instagram-PHP-API

我想检索用户的提要,即使他有私人简介.

首先,我正在生成所有已授予范围的URL

$instagram->getLoginUrl(array('basic','likes', 'relationships', 'comments'));
Run Code Online (Sandbox Code Playgroud)

然后,一旦用户批准了该应用程序,我就会尝试检索他的Feed

// Grab OAuth callback code
$code = $_GET['code'];

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

// Set token
$instagram->setAccessToken($data->access_token); 


// get medias
$medias = $instagram->getUserMedia($data->user->id, -1);
Run Code Online (Sandbox Code Playgroud)

我收到一个APINotAllowedError错误

object(stdClass)#5 (1) {
  ["meta"]=>
  object(stdClass)#6 (3) {
    ["error_type"]=>
    string(18) "APINotAllowedError"
    ["code"]=>
    int(400)
    ["error_message"]=>
    string(29) "you cannot view this resource"
  }
}
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?非常感谢你!

更新和修复

好吧实际上它来自PHP库,当前的getUserMedia()失败,因为它不使用提供的access_token ...

这是正确的方法

public function getUserMedia($id = 'self', $limit = 0) {
    return $this->_makeCall('users/' . $id . '/media/recent', true, array('count' => $limit));
  }
Run Code Online (Sandbox Code Playgroud)

谢谢!

kri*_*rak 5

更新:2016年6月1日之后.即使您正在关注/批准该用户,您也无法再通过API访问私人资料.你会收到错误APINotAllowedError.如果您关注的话,查看私人资料的唯一方法是使用Instagram app或instagram.com.

但如果您的个人资料是私人的,您可以使用您的个人资料访问它 access_token


如果用户是私有的,则无法访问配置文件.当访问具有无权访问用户的access_token的私有用户时,这是正确的响应

{"meta":{"error_type":"APINotAllowedError","code":400,"error_message":"you cannot view this resource"}}
Run Code Online (Sandbox Code Playgroud)

仅当您使用允许访问用户的用户access_token访问API时,才能获得正确的响应.