Instagram access token with invalid error - instagram

How can I display Instagram images of my account to my website homepage using access token and user id?
I followed this guide and get Instagram access token and user id https://developers.facebook.com/docs/instagram-basic-display-api/getting-started
With this guide I get my long-lived access token
but when I run below code in PHP
$access_token="--elided--";
$photo_count=6;
$json_link="https://api.instagram.com/v1/users/self/media/recent/?";
$json_link.="access_token={$access_token}&count={$photo_count}";
echo json_link;
It shows:
{"meta": {"code": 400, "error_type": "OAuthAccessTokenException", "error_message": "The access_token provided is invalid."}}
How can I show Instagram media on my website?

That guide didn't work for me either. Eventually, I figured this out following the procedure described here.
A few key points to keep in mind:
Tokens are being generated from Facebook for Developers
, with no need for a post request like before.
To fetch the photos, you need to make more than one call to the API: One for fetching the photos' IDs and then, one separate call for each ID to get the actual data (permalink, image URL, caption, etc).
There is a limit to the calls that you can make per hour, which, as I realized, can be easily reached on a site with moderate traffic. So, you need to somehow cache the results (on WordPress, I used a transient for that, which seems to work fine).
The token expires after 60 days and you need to refresh it on time for your app to keep working.

Im kind of late but perhabs try to use different API URL. I was also stuck on this problem, trying to use
https://api.instagram.com/v1/users/self/media/recent/?...
But later found this address
https://graph.instagram.com/me/media?fields=media_url,media_type&access_token=...
It works for me with this URL. Other stuff to put into fields=
I would reccomend testing with either curl in cmd or downloading Postman
Also if you followed that guide, you'll end up with short-lived token. There is a way to exchange it for long-lived token in this tutorial
But all you really need to do is get the URL ready
https://graph.instagram.com/access_token?grant_type=ig_exchange_token&
client_secret={client_secret}&
access_token={token}
where
client_secret is your instagram secret (developers.facebook.com => my apps => => on the left panel click "Instagram basic display")
token is that short-lived token you get from the tutorial mentioned in question (this one)

Related

Issue with commenting on Facebook posts with api

I'm a beginner on Facebook API but after reading up and understanding whatever I could I'm still stuck because I can't find any good documentation that is not outdated.
I'm trying to comment on my own post and I keep getting this error:
Publishing comments through the API is only available for page access tokens
I do understand that I require a page access token for the latest version of the API but even after getting the page access token I'm still facing this issue.
Here is a screenshot of my graph API explorer
Here I first clicked on get user access token and gave it all possible permissions. After that I clicked on get page access token and then tried to post the comment.
Note: The post was made by my ID and is visible only to me, I am sure that the user ID and post ID is correct because I am able to view its details
I also tried it using python with the token ID above and this code.
import facebook
graph = facebook.GraphAPI(access_token=token_id)
#This does give me the post details
#print (graph.get_object(id = my_id +'_10214865328931217'))
graph.put_object(parent_object=my_id+'_10214865328931217',connection_name='comments', message='Test')
But I still get the same error. Seems like there is something about the way page access tokens work that I do not understand.

How do I fetch my own Instagram media feed

I have a use case that Instagram does not seem to acknowledge. I am hoping that someone else has an idea for what I can do.
The website that I am maintaining has been using the API endpoint:
https://www.instagram.com/anyUser/media/
And I am aware that Instagram has recently stopped supporting this endpoint. So I am looking for a replacement.
My use case is that I do not want to allow the users of my website to authenticate and browse their own photos. Instead I want to show only the latest 20 images that "I" (aka my employer) have posted, one at a time in a loop.
Instagram's API documentation seems to be entirely focused on the use case of allowing users to authenticate and share their photos.
Is there an API call that will return the last 20 images that I have posted?
From its specs, the Sandbox will work fine for me, I cannot find a way to register with Instagram that does not require me to build a user authentication work flow that will NEVER be used.
You would want to use self feed endpoint.
https://www.instagram.com/developer/endpoints/users/#get_users_self
https://api.instagram.com/v1/users/self/?access_token=ACCESS-TOKEN

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?
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.
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.
Login to your Instragram account you are using as the application.
Go to the developer (API) area. https://www.instagram.com/developer/clients/manage/
Manage clients. Make sure your website URL is the same as your valid redirect URL.
Add new Sandbox User. Put in the account of the IG photos you want to reach.
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.
You should get back and access token URL. Copy your access token.
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.
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.
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
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
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

Obtaining a Nest Access Token for sample

I'm just exploring the Nest Developers APIs, so thought I'd start with running the nestlabs/nest-twitter sample.
I've hit a couple of problems already! One is building the source, and the other is obtaining the Nest access token. I'll address the questions separately, so starting with the Auth problem...
I've created a developer account, and defined a new demo Product. From there I have used the Authorization URL https://home.nest.com/login/oauth2?client_id=[myClientId]&state=STATE, and from my regular Nest account successfully generated an eight character Pincode.
Back to the Product page, I plug the Pincode into the Authorization Token URL
https://api.home.nest.com/oauth2/access_token?client_id=[myid]&code=[myPincode]&client_secret=[mySecret]&grant_type=authorization_code
The response I get is "message":"404 Not Found".
What am I doing wrong?
You're most likely using an HTTP GET or PUT. Make sure you are using POST.

Unable to like media in instagram from any access token

Since 3 or 4 days ago i'm not able to like any photos from any token, I think they blocked me to like. I still can follow/unfollow users via my application. I also can like photos via instagram iOS app.
This is the error i have:
"meta": {
"error_type":"APINotAllowedError",
"code": 400,
"error_message":"you cannot like this media"}
Do you know if they will unlock me or it's permanently?
Instagram changed the terms for using POST and DELETE requests. You can read more about it here http://developers.instagram.com/post/116410697261/publishing-guidelines-and-signed-requests
If you want to request access to those endpoints you can do it here, if your app is qualified.
https://www.facebook.com/help/instagram/contact/185819881608116#=
See API Terms of Use:
Do not abuse the API. Too many requests too quickly will get your access turned off
Wait for some days and see if they will free you... If you are still having trouble, i would suggest to create a new client and see what happens.

Resources