Closed aghayeff closed 7 years ago
I'm with same issue :/
Same as well.
Same as well.
I get the same error while trying to access public APIs like getPopularMedia()
and getUser($id)
. I am not setting an access token because it's not necessary, and I don't have one.
$gram = new Instagram('CLIENT_ID');
var_dump($gram->getPopularMedia());
Same..
getUserLikes
works fine,
searchTags()
displays:
The access_token provided is invalid
I think Instagram has changed the API and access tokens are necessary even for public endpoints.
If you provide the library a client_id and access_token and use something that doesn't require authentication, like getUser()
, then it uses the client_id in the request. There should be a way to force the library to use access_token if it has supplied, since that provides more information from the API in all cases.
Super quick hack I did was in function getUser(), I set the $auth = true;
@Krisseck you absolutely right! Thanks! According to Instagram Platform(API) changelog from Nov 17, 2015 we can see...
...
Apps created on or after Nov 17, 2015
- Start in Sandbox mode for dev & test
- Need to be reviewed and permission scopes approved before used in production
- All API endpoints require a valid access_token
...
So if you want to use this library for your application, you need to do small hack that @Krisseck described above. Because in library code access_token
used not in every case(just look in 👇 code)...
...
protected function _makeCall($function, $auth = false, $params = null, $method = 'GET')
{
if (!$auth) {
// if the call doesn't requires authentication
$authMethod = '?client_id=' . $this->getApiKey();
} else {
// if the call needs an authenticated user
if (!isset($this->_accesstoken)) {
throw new InstagramException("Error: _makeCall() | $function - This method requires an authenticated users access token.");
}
$authMethod = '?access_token=' . $this->getAccessToken();
}
...
As for Me... I prefer to make changes in _makeCall
method and change...
$auth=false
on
$auth=true
After this small change every endpoint request uses acces_token
! Of course if you setup access_token
😄
This is not good practice! But this is choice if author of the library does not support it and doesn't approve(for a long time) any PR
I successfully can get the media by tags with my access_token using link at below:
But, while using this api, i receive an error: The access_token provided is invalid
Here is my code:
What is wrong in my code?