大家好,任何人都可以告诉我如何像使用 api 一样发布喜欢和删除 Instagram 吗?我尝试使用此代码删除类似但我没有从 ajax 调用中得到任何响应。谁能告诉我我在这里做错了什么?这可能在做 php 吗?如何?
xxxxxxxxxxxxxxxxxx_xxxxxxxx ==> Media-Id 例如:23424343243243_2343243243
<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;
}