Instagram API throwing OAuthAccessTokenException 400 error using client id

18,295

Solution 1

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.

Solution 2

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.

Solution 3

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

Solution 4

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
Share:
18,295
Admin
Author by

Admin

Updated on June 09, 2022

Comments

  • Admin
    Admin about 2 years

    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?

  • John Paul Hayes
    John Paul Hayes about 8 years
    Sigh.. looks like sandbox mode is borked too. /user/ endpoints seems to be working but calls like /v1/tags/selfies/media/recent?access_token=XXXX are not returning any data despite having the correct scope in place (i.e. public_content)
  • Admin
    Admin about 8 years
    The idea is to show the latest posts from a public account which belongs to the website where it would be shown. Are you saying there needs to be an authentication there. The website is public facing and should show the posts without any user intervention. This was all working till yesterday since the website was launched last year.
  • James Danylik
    James Danylik about 8 years
    Yes, unfortunately that's exactly what I'm saying. Even though that information is publicly available on Instagram's website, they've discontinued ANY API access to user data without approval from the user (and approval from Instagram to even be eligible.) I have the exact same behavior with my application; fine for literally years, completely broken yesterday.
  • Admin
    Admin about 8 years
    Thanks for the update James. But this is crazy, how are you handling it then? Is there a way to overcome this?
  • James Danylik
    James Danylik about 8 years
    It really depends on what you need. Sadly, you may be forced to redesign around the new permissions scheme if your app needs complete access to user data. If you just need public data, you may be able to extract it with something like Selenium+PhantomJS from search engine caches or something, but I'd definitely check the Terms of Service to see what the rules are. (I'd bet you can't get photos or posts, maybe meta information? Maybe nothing.) Sadly, if you need generic access to actual Instagram posts, getting approved is your only real option.
  • Admin
    Admin about 8 years
    Thanks James. One last question. In the sandbox mode one can add upto 10 users who need to authorize themselves to expose their data. In the GO LIVE mode, do you know how to send invites to the new users apart from the 10 sandbox users, would it be from the Sandbox tab only?
  • donlaur
    donlaur about 8 years
    I was able to get the media endpoint to work by adding a sandbox user and then approving it by loggin in on that user. I posted my solution below which i was able to get this working again and out of this error, but only in sandbox mode and only if the user approves the sandbox invite. It is rate limited but I am only pulling 2 images per account.
  • gregdev
    gregdev almost 8 years
    Thanks, this was perfect for me. To get this working I needed to edit my Instagram client, go to the Security tab, and uncheck the "disable implicit OAuth" option.
  • user151841
    user151841 over 7 years
    What is the "valid redirect URL"?