Getting “APINotAllowedError” when requesting medias on a private profil, even with all scopes allowed

拟墨画扇 提交于 2019-12-22 09:49:59

问题


I'm using the PHP Instagram API https://github.com/cosenary/Instagram-PHP-API

I would like to retrieve the feed of a user, even if he has a private profil.

First, I'm generating the url with all the scopes granted

$instagram->getLoginUrl(array('basic','likes', 'relationships', 'comments'));

Then, once the user approved the application, I try to retrieve his 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);

I get an APINotAllowedError error

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

What am I doing wrong? Thank you very much!

UPDATE AND FIX

Ok actually it comes from the PHP library, the current getUserMedia() fails because it doesn't use the access_token provided...

Here is the correct method

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

Thank you!


回答1:


UPDATE: After June 1, 2016. You can no longer access a private profile via API even if you are following/approved by that user. You will get error APINotAllowedError. Only way to view private profile if you are following is by using instagram app or instagram.com.

But if your profile is private, you can access it via API using your access_token


You cannot access a profile if user is private. This is the right response when accessing a private user with a access_token that does not have access to the user

{"meta":{"error_type":"APINotAllowedError","code":400,"error_message":"you cannot view this resource"}}

You can get the correct response only if you access the API with a user's access_token that has been allowed to access the user.



来源:https://stackoverflow.com/questions/23701131/getting-apinotallowederror-when-requesting-medias-on-a-private-profil-even-wi

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!