Instagram API from client side

[亡魂溺海] 提交于 2019-12-03 21:13:50

问题


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?


回答1:


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.




回答2:


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');
      }

      }
    });


来源:https://stackoverflow.com/questions/22847070/instagram-api-from-client-side

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!