Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call Instagram API without ACCESS_TOKEN

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

like image 218
Christian Sakai Avatar asked Oct 31 '25 15:10

Christian Sakai


1 Answers

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!

like image 51
coderz Avatar answered Nov 04 '25 06:11

coderz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!