繁体   English   中英

如何发布喜欢或使用instagram api删除instagram之类的instagram?

[英]how to post a like or delete an instagram like using instagram api?

大家好,有人可以告诉我如何使用api发布喜欢的图片并删除instagram吗? 我试图使用此代码删除一个喜欢,但我没有收到来自ajax调用的任何响应。 谁能告诉我我在这里做错了吗?这有可能在做php吗?怎么办?

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

删除喜欢的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>

编辑:跨域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;
}

编辑:根据API规范,您需要使用DELETE类型的请求。 为此,请指定{type: "DELETE"} ,而不是{"method": "delete"}并使用$.ajax()函数。 在此处查看相关问题: 如何在jQuery中发送PUT / DELETE请求?

您确定已完全执行POST请求吗? 它可能根本没有运行,请在Developer Tools / Firebug / etc中检查请求。并以jQuery方式初始化请求,请勿使用干扰性的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()结果感兴趣-很可能您在准备请求时错过了某些内容。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM