[英]Instagram API from client side
我正試圖從客戶端調用Instagram API端點。 我只能使用Instagram推薦的 JSONP訪問基於GET的端點。 對於那些需要POST或DELETE的人來說,似乎沒有啟用CORS,因此這些類型的ajax調用失敗。
我可以使用任何方法或方法從客戶端訪問這些API嗎?
無法直接從客戶端進行POST調用,您必須設置一個代理服務器,使Instagram API調用POST和DELETE,並且您的客戶端應用程序可以調用代理服務器。
我不明白你的問題,但我在客戶端使用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');
}
}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.