Call Instagram API without ACCESS_TOKEN

10,205

If I get your question correctly, you want to fetch your own recent media that you have posted on Instagram using the new API endpoints using an access token.

So, the solution to this is pretty simple. You don't need your visitors to log in their Instagram every time to view your media on Instagram.

Using Access Token(Using server side explicit method, preferred):

  • Request Access Code:

    var redirect_uri = "&redirect_uri="<REDIRECT-URI>,
        scope = "&scope=basic",
        response_type = "&response_type=code",
        url = "https://api.instagram.com/oauth/authorize/?client_id=" + <CLIENT-ID> + redirect_uri + response_type + scope;
    
  • Exchange CODE for token: Extract the code from http://your-redirect-uri?code=CODE and exchange this code to get the access token using server side method like cURL (preferred)

    • Use the endpoint: https://api.instagram.com/oauth/access_token.
    • Pass the following parameters,

      • client_id
      • client_secret
      • grant_type as "authorization_code"
      • redirect_uri
      • code

Without Using Access Token(Using implicit method):

  • Request Access Token: Use https://api.instagram.com/oauth/authorize/?client_id=CLIENT-ID&redirect_uri=REDIRECT-URI&response_type=token
  • Get Access Token: Extract token using http://your-redirect-uri#access_token=ACCESS-TOKEN

Fetch your published media: Use endpoint as https://api.instagram.com/v1/users/self/media/recent/?access_token=<ACCESS-TOKEN> (you can pass optional parameters like count if required)



Here your visitors don't need to log in their accounts. Once you have the link, save them in your database so you don't have to log in every time.

Hope it helps!

Share:
10,205
Christian Sakai
Author by

Christian Sakai

Updated on June 06, 2022

Comments

  • Christian Sakai
    Christian Sakai about 2 years

    Instagram recently change their API so it does not use client_id anymore but instead access_token.

    I just want to get a list of instagram pictures that I have and put it on my website.

    This is my previous ajax call using jsonp

    'https://api.instagram.com/v1/users/'+_instagram._id+'/media/recent/?client_id='+_instagram._clientId

    How do I do it now with access_token? I don't want a visitor of my website to log in into instagram everytime just to view my instagram pictures that will be available on my website

  • nipeco
    nipeco over 7 years
    What, if the access_token expires?
  • coderz
    coderz over 7 years
    @leFake, you have to ask the users to log in again and repeat the process above