spal
spal

Reputation: 71

Instagram API throwing OAuthAccessTokenException 400 error using client id

I was using the following api to get the latest 3 posts from public accounts to show on the website:

https://api.instagram.com/v1/users/{user-id}/media/recent/?client_id={client-id}&count=3

I had created an app to get the client-id.
However from today, this API has started throwing the following exception:

{
    meta: {
        error_type: "OAuthAccessTokenException",
        code: 400,
        error_message: "The access_token provided is invalid."
    }
}

Could you please let me know as how to resolve this?

Upvotes: 7

Views: 19773

Answers (5)

Akshay I
Akshay I

Reputation: 4175

If you want to retrieve the user media file then try this, It's working for me

https://graph.instagram.com/me/media?fields=id,caption,media_url,media_type&access_token=ACCESS_TOKEN

Upvotes: 1

donlaur
donlaur

Reputation: 1287

I have a solution to this. If you are using the same code I am, which appears likely. I was pulling the last two images using this.

https://api.instagram.com/v1/users/{user-id}/media/recent/?client_id={client-id}&count=3

What I did to get this working is the following.

  1. Login to your Instragram account you are using as the application.

  2. Go to the developer (API) area. https://www.instagram.com/developer/clients/manage/

  3. Manage clients. Make sure your website URL is the same as your valid redirect URL.
  4. Add new Sandbox User. Put in the account of the IG photos you want to reach.
  5. Hit this URL: https://api.instagram.com/oauth/authorize/?client_id=CLIENTID&redirect_uri=REDIRECT_URI&response_type=token where the client ID is the same one you used in your previous app above.
  6. You should get back and access token URL. Copy your access token.
  7. Login as your account that you want the IG photos of. The account you added as a sandbox user and go to developer and approve the Sandbox Invites.
  8. Change your original URL above from https://api.instagram.com/v1/users/{user-id}/media/recent/?client_id={client-id}&count=3 to https://api.instagram.com/v1/users/self/media/recent/?access_token=ACCESS_TOKEN with your access token.

This is the IG API Media endpoint documentation: https://www.instagram.com/developer/endpoints/users/

After that, it all worked for me and while you are in the sandbox, you should be able to pull the last 3 photos or at this point, figure out how to read the JSON to do so.

Upvotes: 7

James Danylik
James Danylik

Reputation: 371

Based on the date, you probably have an older app that got hit by the API migration today, like mine. In short, Instagram decided to make developing for their platform WAY more annoying by requiring all API requests to be authenticated per user, even for data that users shares publicly. So you (like me) will likely be redesigning you app entirely.

To tell, log in to instagram.com/developer and click manage clients; then hit edit next to the set of keys your're trying to use. Up near the top, it will have a section called 'Client Status' -- if yours reads 'Sandbox Mode', fun times ahead! Hopefully you interact with less than 10 users and can stay in sandbox mode, otherwise you'll have to write an essay, film a video, and basically plead to get your permissions back (probably in a few months, when some Instagram intern finally digs his way down to you in the pile of applications). If it reads something eles, you've got another problem altogether and should thank your lucky stars.

In the meantime, I guess I'll get back to sending out dozens of emails to the maintainers of our many, many affiliated Instagram accounts to explain the issue and try to get permissions, so provided we get approved by then, all our social media displays aren't broken during a huge event Saturday. Another option might be to use the OAuth-less json response available here, but that might break terms of service.

Upvotes: 13

Evonet
Evonet

Reputation: 3640

Has your app been approved after the June 1st Instagram platform changes?

http://developers.instagram.com/post/145262544121/instagram-platform-update-effective-june-1-2016

Upvotes: 1

Atl Occ
Atl Occ

Reputation: 11

For some reason the token is no more valid. Request it again.

Possible reasons why a token is no more valid:

  • changed password
  • verified the account
  • logged-in from a different country

Upvotes: 0

Related Questions