我试图从客户端调用Instagram API端点。我只能使用JSONP访问基于GET的端点,Instagram recommends。对于那些需要POST或DELETE的人来说,似乎没有启用CORS,因此这些类型的ajax调用失败。
我是否可以使用任何方法或方法从客户端访问这些API?
答案 0 :(得分:3)
无法直接从客户端进行POST调用,您必须设置一个代理服务器,使Instagram API调用POST和DELETE,并且您的客户端应用程序可以调用代理服务器。
答案 1 :(得分:-1)
我不明白你的问题,但我在客户端使用Instagram API,并使用它进行POST和GET:
$.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');
}
}
});
您可以更改令牌和媒体ID,并在http://jsfiddle.net/DvLE2/
上对其进行测试如果您需要发送数据(动作,关系中),请添加:
data: data;
例如,关系(跟随或取消关注某人):
$.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');
}
}
});