我正在尝试使用AJAX请求删除我的vimeo视频,但它始终返回204状态代码,并且视频并未从帐户中删除。这是代码示例。
$(".js-delete").click(function(){
var videoID = $(this).data("target");// /videos/2332
$.ajax({
type: "post",
url: "https://api.vimeo.com/me/videos",
headers: {
"Authorization": "bearer xxxxxxxxxxxxxxx"
},
data: {
url: "https://api.vimeo.com/me"+videoID,
method: "DELETE"
},
dataType: "json"
success: function(response){
console.log(response); //will print the whole JSON
},
error: function(){
console.log('Request Failed.');
}
});
});
有人可以建议对此进行一些更改吗?
预先感谢
答案 0 :(得分:4)
您正在发送
POST
https://api.vimeo.com/me/videos
header
Bearer <token>
(大写 B )而不是bearer <token>
。但是根据Delete a Video的Vimeo API文档,请求应为
DELETE https://api.vimeo.com/videos/{video_id}
带注释:
此方法需要具有“删除”范围的令牌。
如果承载令牌正确,则jQuery ajax请求应如下所示:
$(".js-delete").click(function(){
var videoID = $(this).data("target");// /videos/2332
$.ajax({
type: 'DELETE',
url: 'https://api.vimeo.com/videos/' + videoID,
headers: {
"Authorization": "Bearer xxxxxxxxxxxxxxx"
},
success: function(response){
console.log(response); //will print the whole JSON
},
error: function(){
console.log('Request Failed.');
}
});
});
您应该能够使用https://www.getpostman.com/来测试此请求,以验证该请求以及承载令牌在CF应用程序之外是否有效。