如何通过 YouTube API v3 更新已上传视频的代码段和状态值



如何使用 AJAX 请求更改已通过 YouTube API v3 "https://www.googleapis.com/youtube/v3/videos" 上传的视频的代码段和状态值?

我的更新代码(不起作用):

$.ajax({
        type: "PUT",
        dataType: "jsonp", 
        url: "https://www.googleapis.com/youtube/v3/videos?part=id,snippet,status&key=<API Key>",
        headers: {
            "Content-Type": "application/json",
            "Authorization": "Bearer " + <Access Token>
        },
        data: $.parseJSON('{"id": "<Video ID>", "snippet": {"title": "New Title", "description": "New Description"}, "status": {"privacyStatus": "unlisted"}}'), 
        success: function(data, error, completeError) {
            alert( JSON.stringify(data));
            alert( JSON.stringify(error));
            alert( JSON.stringify(completeError));
        }
    });

使用参数 part=id,snippet,statusvideos/update端点发出 PUT 请求:

HTTP PUT: https://www.googleapis.com/youtube/v3/videos?part=id,snippet,status&key={YOUR_API_KEY}

您的请求正文:

{
    "id": "VIDEO_ID",
    "snippet": { // any snippet fields you want to change
        "description": "New Video Description"
    },
    "status": { // any status fields you want to change
        "privacyStatus": "public"
    }
}

这是我玩游戏时使用的代码。不过效果很好。它不使用JQuery,但应该为你指明正确的方向。

function UpdateVideoInfo(video_id){
        var resource = {
                'snippet':{
                    'title' : 'test title',
                    'description' : 'test description',
                    'categoryId' : 22
                },
                'status' : {
                    'privacyStatus' : 'private'
                },
                'id': video_id
            };
        post_string = JSON.stringify(resource);
        var ajax = new XMLHttpRequest();
        ajax.open('PUT', 'https://www.googleapis.com/youtube/v3/videos?part=snippet,status', true);
        ajax.setRequestHeader("Authorization", '<?php echo $authorization_header; ?>');
        ajax.setRequestHeader("Content-type", "application/json; charset=UTF-8");
        ajax.send(post_string);
        ajax.onload = function() {
            if (ajax.status == 200) {
                alert(ajax.responseText);
            }
        };
    }

相关内容

  • 没有找到相关文章

最新更新