Reputation: 536
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!
Upvotes: 3
Views: 5365
Reputation: 12952
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.
Upvotes: 5