I'm trying to put a user's recent Instagram media on a sidebar. I'm trying to use the Instagram API to fetch the media.
http://instagram.com/developer/endpoints/users/
The documentation says to GET https://api.instagram.com/v1/users/<user-id>/media/recent/
, but it says to pass an OAuth access token. An access token represents the authorization to act on behalf of a user. I don't want users to log into Instagram to see this on the sidebar. They shouldn't even need to have an Instagram account.
For instance, I can go to http://instagram.com/thebrainscoop without being logged into Instagram and see photos. I want to do that through the API.
In the Instagram API, non-user-authenticated requests pass a client_id
instead of an access_token
. If I try that, though, I get:
{
"meta":{
"error_type":"OAuthParameterException",
"code":400,
"error_message":"\"access_token\" URL parameter missing. This OAuth request requires an \"access_token\" URL parameter."
}
}
So, is this not possible? Is there no way to fetch a user's latest (public) media without asking a user to log into an Instagram account through OAuth first?
This is late, but worthwhile if it helps someone as I did not see it in Instagram's documentation.
To perform GET on
https://api.instagram.com/v1/users/<user-id>/media/recent/
(at present time of writing) you actually do not need OAuth access token.You can perform
https://api.instagram.com/v1/users/[USER ID]/media/recent/?client_id=[CLIENT ID]
[CLIENT ID] would be valid client id registered in app through manage clients (not related to user whatsoever). You can get [USER ID] from username by performing GET users search request:
https://api.instagram.com/v1/users/search?q=[USERNAME]&client_id=[CLIENT ID]
11.11.2017
Since Instagram changed the way they provide this data, none of above methods work nowadays. Here is the new way to get user's media:
GET
https://instagram.com/graphql/query/?query_id=17888483320059182&variables={"id":"1951415043","first":20,"after":null}
Where:
query_id
- permanent value: 17888483320059182 (note it might be changed in future).id
- id of the user. It may come with list of users. To get the list of users you can use following request:GET https://www.instagram.com/web/search/topsearch/?context=blended&query=YOUR_QUERY
first
- amount of items to get.after
- id of the last item if you want to get items from that id.Thanks to Instagram's ever changing (and horrifically designed) API schema most of the above will no longer work as of April 2018.
Here is the latest path to access individual post data if you are querying their API directly using the
https://www.instagram.com/username/?__a=1
method.Assuming your returned
JSON
data is$data
you can loop through each result using the following path examples :The main things in this recent change were
graphql
andedge_owner_to_timeline_media
.Looks like they are going to be killing this API access off for non 'business' customers in DEC 2018 so make the most of it while you can.
Hope it helps somebody ;)
You can use this API to retrieve public info of the instagram user:
http://pegaqui-api.sa-east-1.elasticbeanstalk.com/instagram?username=thebrainscoop&limit=2
If you don't set the limit parameter, the posts are limited at 12 by default
This api was made in SpringBoot with HtmlUnit as you can see in the code:
It's an example of response:
Update
This method don't work anymore
JSFiddle
Javascript:
HTML:
CSS:
As of last week, Instagram disabled
/media/
urls, I implemented a workaround, which works pretty well for now.To solve everyone's problems in this thread, I wrote this: https://github.com/whizzzkid/instagram-reverse-proxy
It provides all of instagram's public data using the following endpoints:
Get user media:
Get user media with limit count:
Use JSONP:
The proxy API also appends next page and previous page URLs to the response so you do not need to calculate that at your end.
Hope you guys like it!
Thanks to @350D for spotting this :)