I just can't get it right.
There are docs for instagram api that says do one call, it will redirect user to a page where he authenticate, then you get code from Redirect Url and now using this code you can get token. That is working and it is just fine. But, what if i want to do a website for myself as personal page and show my own instagram photos filtered by tag to ANYONE. I don't need OAuth, any login. I'm ok with creating Node server and make a call smth like this:
http://api.instagram.com/auth?client_id_or_login=vvinog&password=secretpassword
and get token from this call. But it looks like in the internet no one do this, or i dump?
Can you please advice some tutorial, approach that allows me to do that?
Any code snippets are super welcome.
Related
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)
I heard that Instagram recently changed their APIs and I have a related question to that.
Let's assume I would like to build an "Instagram feed app of people I follow". So this app would just show me the pictures of all people I follow. From what I understand this would be possible, but I would always have same manual effort:
From the Instagram developer website I understand that I need the access_token from all my friends.
Do I understand that correctly?
This would mean every time I follow someone new, I would have to get his/her access_token manually and add it into my app.
Do I understand this correctly or is there a programmatic/automated way to get the needed access_token from the new followed person?
Yes, you are correct. This is not possible at the moment. I'm not sure how you would get the access token of friends. You would have to have them login as well. BTW: This seems to be the way facebook is going (since they now control Instagram). They require that both friends have authorized your app and then they will list their followers.
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
I really hope someone can tell me more about what's going on, because I spent days searching the net and for the life of me can't say what is going on.
Here's what happened. I have a website 4nieuws.nl . On every article's page I put a like button using the Javascript SDK. All worked well. On facebook I created a fanpage for the website, facebook.com/4nieuws and every now and again I would copy an interesting article there. The like button and Javascript SDK on 4nieuws.nl uses the APP Id from an app I created specifically for that purpose.
Then I thought I might automate to publish the most popular articles on the fanpage using the PHP api. I set about getting the proper authorization key using the sequence explained on this page: http://www.typeoneerror.com/articles/post/permanent-facebook-sessions-and-posting-as-a-page
For this to work I authorized the previously mentioned app to publish on the facebook fanpages that I am admin of. And this works.
Now for the strange part. Ever since I authorized the app, if I go to 4nieuws.nl and like a page, or even 'post to facebook', the button shows 1 more like. But the like message never shows up on my personal wall. My wife, logged in to her own facebook account, gets a notification that I liked a page, but when she clicks the notification she is sent to a Facebook 404 page. When I subsequently reload the article, my 'like' is not there anymore.
Has anyone ever come across something like this ? I'm a bit anxious because I am not sure if other peoples likes on 4nieuws.nl are working as it should. I do see likes on pages but have no idea if those likes are actually registering on peoples walls.
Any help greatly appreciated.
I'm currently dealing with the fascinatingly confusing world of Microsoft. I've read several of the half-baked tutorials on how to use their Graph API and Office 365 API and I still don't really know what to do. What I HAVE figure out is how to build that authorization request URL so I can get the "code", which is supposed to be used to then get the access token. I've done this with the Google API and it works beautifully, but not with the Microsoft Graph API. Here's what I have:
https://login.microsoftonline.com/common/oauth2/authorize?client_id=123451234512345&response_type=code&redirect_uri=https://www.my-site.com/oauth-callback/microsoft
When the user clicks on this link, they are taken to the Microsoft login page. So far, so good. But, after entering my login credentials it just takes me right back to the same Microsoft login page, as opposed to redirecting the user to my redirect uri. I have an Azure account with the same redirect URI specified, but it just isn't working. What am I doing wrong? By the way, I'm using node.js. Any links to useful tutorials would be much appreciated.
To get a code you need to pass the following parameters:
response_type=code
client_id=yourClientId
redirect_uri=yourRedirectUri
resource=https://graph.microsoft.com
For example:
https://login.microsoftonline.com/common/oauth2/authorize?response_type=code&client_id=12334&redirect_uri=https://myapp.com&resource=https://graph.microsoft.com
Finally, thank you for the feedback, can you please point the articles you read where the information was not clear so we can make sure to update them? I suggest you try the following article: https://graph.microsoft.io/docs/platform/rest
This is a great video explaining the login process: https://www.youtube.com/watch?v=HOcwvuIJHXA "Deep Dive into the Office 365 RESTful APIs". It is very long, but detailed. Around 25:00 it shows with Fiddler how the login works. Helped me a lot.