我如何发送删除请求以删除AJAX中的视频,其返回204状态

时间:2019-09-13 03:19:42

标签: ajax api coldfusion vimeo vimeo-api

我正在尝试使用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.');
        }
    });
});

有人可以建议对此进行一些更改吗?

预先感谢

1 个答案:

答案 0 :(得分:4)

您正在发送

  • HTTP POST
  • 访问URL https://api.vimeo.com/me/videos
  • 以Bearer令牌为header
    • 请注意,it should be Bearer <token>(大写 B )而不是bearer <token>
  • 带有包含另一个URL和HTTP方法的数据包。

但是根据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应用程序之外是否有效。