使用WebRTC并将视频上传到YouTube

时间:2018-07-05 19:21:17

标签: php youtube-api webrtc service-accounts

我正在一个项目中,我想使用WebRTC从我的PHP网站录制视频并将其上传到我的YouTube频道。对于下面的代码,由于视频已保存在我的服务器上,因此我只想尝试上载。我不清楚我需要使用哪种密钥或授权。阅读并研究了文档之后,我认为我需要使用服务帐户(密钥)来完成此工作吗? https://developers.google.com/api-client-library/php/auth/service-accounts

我不希望用户登录/认证Google帐户。我希望从我的网站上传到我的YouTube频道。

我无权使用composer进行安装,因此我已经在服务器上上传了google-api-php-client(v2.2.2)文件夹。

我目前无法找到任何更接近我所需的示例,因此我试图将这些片段混在一起:

上传到云端硬盘:https://developers.google.com/api-client-library/php/guide/media_upload 使用服务帐户密钥(?):https://developers.google.com/api-client-library/php/auth/service-accounts 上传视频:https://developers.google.com/youtube/v3/code_samples/php#upload_a_video

我得到任何指导表示赞赏。我收到“此页面无效”的HTTP错误500

这是我的代码当前的样子:

<?php

    if (!file_exists('google-api-php-client/vendor/autoload.php')) {
    throw new \Exception('please run "composer require google/apiclient:~2.0" in "' . __DIR__ .'"');
    }

    require_once 'google-api-php-client/vendor/autoload.php';

    session_start();

    putenv('GOOGLE_APPLICATION_CREDENTIALS=I-Video/i-video-recording-0e9cbc2cad7a.json');
    $client = new Google_Client();
    $client->useApplicationDefaultCredentials();


    $file = new Google_Service_YouTube($client);
    $result = $service->files->insert($file, array(
    'data' => file_get_contents("data/1530103005236.webm"),
    'mimeType' => 'application/octet-stream',
    'uploadType' => 'media'
    ));
?>

0 个答案:

没有答案