如何使用Instagram API发布喜欢或删除Instagram?

大家好,任何人都可以告诉我如何发布喜欢和删除像使用API​​的Instagram? 我试图删除使用此代码,但我没有从ajax调用得到任何响应。 任何人都可以告诉我我在这里做错了什么?这可能是做php吗?怎么样?

xxxxxxxxxxxxxxxxxx_xxxxxxxx ==> Media-Id,例如:23424343243243_2343243243

用于删除喜欢的Instagram API文档

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

编辑:跨域php curl :(但如果这是post方法或删除方法怎么告诉它?“

 $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()函数。 在这里查看相关问题: 如何在jQuery中发送PUT / DELETE请求?

你确定你的POST请求完全被执行了吗? 它可能根本没有运行,请检查Developer Tools / Firebug /等中的请求。并初始化您的请求jQuery方式,不要使用obtrusive JS:

 $(function(){ deleteLike(); }); 

使用success参数的方式需要使用更多参数声明函数: success(data, textStatus, jqXHR) 。 这也可能导致不当行为。 请阅读这里的文档: http : //api.jquery.com/jQuery.post/

我建议你使用更方便的.done()函数:

 $.post(url, { "method": "delete"}) .done(function(data) { var ajaxResponse = data; alert("success: " + ajaxResponse); }) .fail(function() { // check for error here }); 

你也应该对检查.fail()结果感兴趣 – 很可能你在准备请求时错过了一些东西。