从浏览器将视频上传到 youtube [英] Uploading a video to youtube from browser

查看:34
本文介绍了从浏览器将视频上传到 youtube的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我没问题.

我的页面上有 2 个这样的按钮:

I have 2 button's like this on my page:

<input type="file" id="fileToSend"/>
<input type="button" onclick="upload()" value="Upload" id="btnSend"/>

我想在单击上传"按钮时将所选文件上传到 youtube.我调用这样的函数:

I want to upload the selected file to youtube when I click the "Upload" button. Im calling a function like this:

function upload() {
    var fileStream;
    var video = document.getElementById("fileToSend");
    var file = video.files[0];
    console.log(file);
    console.log("Nombre: " + file.name);
    var r = new FileReader();
    r.onload = function () {
        console.log("fileStream creado");
        fileStream = r.result;
        //console.log("FileStream: " + fileStream);
    };

    console.log("Creando fileStream..");
    r.readAsBinaryString(file);


    gapi.client.load('youtube', 'v3',
        function() {
            var request = gapi.client.youtube.videos.insert({
                part: 'snippet, status',
                resource: {
                    snippet: {
                        title: 'Video Test Title 5',
                        description: 'Video Test Description',
                        tags: ['Tag 1', 'Tag 2'],
                        categoryId: "22"
                    },
                    status: {
                        privacyStatus: "private"
                    }
                }
            }, fileStream);
            request.execute(function (response) {
                console.log("executing..");
                var result = response.result;
                console.log(response);
                if (result) {
                    console.log("execute completed");
                    document.write(result);
                }
            });
        });
}

问题是我在响应对象mediaBodyRequired"上遇到了错误,就像我没有正确发送文件流一样.

The problem is I get al error on the response object, "mediaBodyRequired", It's like I'm not sending the fileStream correctly.

推荐答案

是否有理由不能只使用 YouTube 上传小部件?
https://developers.google.com/youtube/youtube_upload_widget

Is there a reason you can't just use the YouTube upload widget?
https://developers.google.com/youtube/youtube_upload_widget

无论如何,直接来自 API 参考
https://developers.google.com/youtube/v3/docs/videos/insert

Anyways, straight from the API reference
https://developers.google.com/youtube/v3/docs/videos/insert

badRequest  mediaBodyRequired   The request does not include the video content.

另一个资源:
https://developers.google.com/api-client-library/javascript/样品/样品

这篇关于从浏览器将视频上传到 youtube的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆