[英]how to post a like or delete an instagram like using instagram api?
hi all could any one tell me how i can post a like and delete an instagram like using api? 大家好,有人可以告诉我如何使用api发布喜欢的图片并删除instagram吗? i tried to delete a like using this code but i dont get any response from ajax call.
我试图使用此代码删除一个喜欢,但我没有收到来自ajax调用的任何响应。 could any one tell me what i am doing wrong here ?is this possible doing php ?how?
谁能告诉我我在这里做错了吗?这有可能在做php吗?怎么办?
xxxxxxxxxxxxxxxxxx_xxxxxxxx ==> Media-Id such as: 23424343243243_2343243243 xxxxxxxxxxxxxxxxxx_xxxxxxxx ==> Media-Id,例如:23424343243243_2343243243
Instagram API Docs for Deleting Like 删除喜欢的Instagram API文档
<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>
Edited:cross domain php curl:(but how to tell it if this is post method or delete method?" 编辑:跨域php curl :(但是如何分辨这是post方法还是delete方法?”
$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;
}
EDIT: According to API specs, you need to use request of DELETE
type. 编辑:根据API规范,您需要使用
DELETE
类型的请求。 To do this, specify {type: "DELETE"}
, not {"method": "delete"}
and use $.ajax()
function. 为此,请指定
{type: "DELETE"}
,而不是{"method": "delete"}
并使用$.ajax()
函数。 See related question here: How to send a PUT/DELETE request in jQuery? 在此处查看相关问题: 如何在jQuery中发送PUT / DELETE请求?
Are you sure you've got your POST request gets executed at all? 您确定已完全执行POST请求吗? 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:
它可能根本没有运行,请在Developer Tools / Firebug / etc中检查请求。并以jQuery方式初始化请求,请勿使用干扰性的JS:
$(function(){
deleteLike();
});
The way you use success
parameter you need to declare functions with more parameters: success(data, textStatus, jqXHR)
. 使用
success
参数的方式需要声明具有更多参数的函数: success(data, textStatus, jqXHR)
。 This may also cause misbehavior. 这也可能导致行为异常。 Please read docs here: http://api.jquery.com/jQuery.post/
请在此处阅读文档: http : //api.jquery.com/jQuery.post/
I'd suggest you to use more handy .done()
function: 我建议您使用更方便的
.done()
函数:
$.post(url, { "method": "delete"})
.done(function(data) {
var ajaxResponse = data;
alert("success: " + ajaxResponse);
})
.fail(function() {
// check for error here
});
You should also definitely be interested in checking .fail()
result - most probably you've missed something while preparing request. 您当然也应该对检查
.fail()
结果感兴趣-很可能您在准备请求时错过了某些内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.