如何使用Instagram API发布喜欢或删除Instagram? [英] how to post a like or delete an instagram like using instagram api?
问题描述
大家都可以告诉我如何使用api发布喜欢和删除Instagram?
我试图删除使用此代码的类似但我没有从ajax调用得到任何响应。任何人都可以告诉我这里做错了什么?这可能做php吗?怎么做?
hi all could any one tell me how i can post a like and delete an instagram like using api? i tried to delete a like using this code but i dont get any response from ajax call. could any one tell me what i am doing wrong here ?is this possible doing php ?how?
xxxxxxxxxxxxxxxxxx_xxxxxxxx ==> Media-Id如:23424343243243_2343243243
xxxxxxxxxxxxxxxxxx_xxxxxxxx ==> Media-Id such as: 23424343243243_2343243243
Instagram API Docs for Deleting Like
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
<script type="text/javascript">
function deleteLike() {
alert("inside function");
var url = "https://api.instagram.com/v1/media/xxxxxxxxxxxxxxxxxx_xxxxxxxx/likes?access_token=XXXX";
$.post(url, {
"method": "delete",
}, function(data)
{
var ajaxResponse = data;
alert("success"+ajaxResponse);
})
}
</script>
</head>
<body onload="deleteLike();">
</html>
编辑:跨域php curl :(但如果这是post方法或删除方法怎么告诉它?
Edited:cross domain php curl:(but how to tell it if this is post method or delete method?"
$url = "https://api.instagram.com/v1/media/xxxxxxxxxxxxxxxxxx_xxxxxxxx/likes?access_token=XXXX";
$api_response = get_data(''.$url);
$record = json_decode($api_response); // JSON decode
/* gets the data from a URL */
function get_data($url) {
$ch = curl_init();
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
推荐答案
编辑:根据API规范,您需要使用 DELETE
类型的请求。为此,请指定 {type:DELETE}
,而非 {method:delete}
并使用 $ .ajax()
函数。请在此处查看相关问题:如何发送PUT / DELETE请求jQuery?
According to API specs, you need to use request of DELETE
type. To do this, specify {type: "DELETE"}
, not {"method": "delete"}
and use $.ajax()
function. See related question here: How to send a PUT/DELETE request in jQuery?
你确定你的POST请求完全被执行了吗?它可能根本没有运行,请检查开发人员工具 / Firebug /等中的请求。并初始化您的请求jQuery方式,不要使用obtrusive JS:
Are you sure you've got your POST request gets executed at all? It may be not running at all, please check requests in Developer Tools / Firebug / etc. And initialize your request jQuery way, don't use obtrusive JS:
$(function(){
deleteLike();
});
您使用成功
参数的方式声明具有更多参数的函数: success(data,textStatus,jqXHR)
。这也可能导致不当行为。请阅读此处的文档: http://api.jquery.com/jQuery.post/
The way you use success
parameter you need to declare functions with more parameters: success(data, textStatus, jqXHR)
. This may also cause misbehavior. Please read docs here: http://api.jquery.com/jQuery.post/
我建议你使用更方便的 .done()
功能:
I'd suggest you to use more handy .done()
function:
$.post(url, { "method": "delete"})
.done(function(data) {
var ajaxResponse = data;
alert("success: " + ajaxResponse);
})
.fail(function() {
// check for error here
});
您还应该对检查 .fail()$感兴趣c $ c>结果 - 很可能你在准备请求时错过了一些东西。
You should also definitely be interested in checking .fail()
result - most probably you've missed something while preparing request.
这篇关于如何使用Instagram API发布喜欢或删除Instagram?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!