Eric Di Bari
Eric Di Bari

Reputation: 3867

Instagram API from client side

I'm trying to call Instagram API endpoints from the client side. I can only access GET-based endpoints using JSONP, which Instagram recommends. For those requiring POST or DELETE, it seems CORS isn't enabled, so these types of ajax calls fail.

Is there any method or approach I can use to access these APIs from the client side?

Upvotes: 5

Views: 4191

Answers (2)

Inkeliz
Inkeliz

Reputation: 1135

I not understand your question, but i use the Instagram API in Client Side, and i make POST and GET, using it:

 $.ajax({
  type: "POST",
  "method": "POST",

  //Use the URL in Instagram Document
  url: 'https://api.instagram.com/v1/media/<ID>/likes?access_token=<TOKEN>',
  dataType: "jsonp", 

  //To get response
  success: function(result){

  //Exemple, if is okay or not
  if(result.meta.code == 200){
  alert('ok');  
  }else{
  alert('fail'); 
  }

  }
});

You can change the token and media id, and test it on http://jsfiddle.net/DvLE2/

If you need send data (action, in relationship), you add:

data: data;

Exemple, for Relationship (to follow or unfollow someone):

$.ajax({
      type: "POST",
      "method": "POST",

      url: 'https://api.instagram.com/v1/users/<ID>/relationship?access_token=<TOKEN>',
      //action (you need that to use relationship 
      data: {action: 'follow'},
      dataType: "jsonp", 
      success: function(result){
      if(result.meta.code == 200){
      alert('ok');

      }else{
      alert('fail');
      }

      }
    });

Upvotes: -1

krisrak
krisrak

Reputation: 12952

Not possible to make POST calls directly from client side, You have to setup a proxy server that makes the Instagram API calls for POST and DELETE, and your client side app can call the proxy server.

Upvotes: 3

Related Questions