如何使用Google Drive API托管或流式传输在Google Drive中上传的视频

阿舒托什夏娃

我正在使用网络应用程序,我需要通过Google Drive API流式传输在Google Drive中上传的视频。我已经创建了服务帐户来上传文件,查看文件并授予权限。而是我授予了在特定域共享文件的权限,我尝试按照以下步骤从子域访问文件。这里以我为例,我正在使用w3school.com来访问流视频。
以下是我授予域权限的代码:**我也曾尝试授予电子邮件权限,然后成功播放了视频**

https://developers.google.com/drive/api/v3/manage-sharing

 $domainPermission = new Google_Service_Drive_Permission(array(
        'type' => 'domain',
        'role' => 'reader',
        'domain' => 'w3schools.com'
    ));
    $request = $driveService->permissions->create(
        $fileId, $domainPermission, array('fields' => 'id'));
    $batch->add($request, 'domain');
 $results = $batch->execute();

要使Weblink能够流式传输视频,请按照以下::

$service = new Google_Service_Drive($client);

$fileId = 'xxxxxxxxxxxxxxxxxw5e4zLE5mLv9lYob';

$argument = array(
                  "fields"=>"webViewLink",
                  );
  $file = $service->files->get($fileId,  $argument);

  echo "<pre>";
  print_r($file);

it give's webviewlink as follow's 
https://drive.google.com/file/d/xxxxxxxxxxxxxxxxw5e4zLE5mLv9lYob/view?usp=drivesdk

Now to stream video example html code is like this 
<!DOCTYPE html>
<html>
<body>

<video width="320" height="240" controls>
  <source src="https://drive.google.com/file/d/xxxxxxxxxxx5mLv9lYob/view?usp=drivesdk" type="video/mp4">
</video>


</body>
</html>`

我无法在我的子域或主域中播放此视频,例如:webaccess.w3schools.com或w3schools.com

在此过程中可能出现什么错误。请帮助谢谢。

Tanaike

我认为您的问题是由于跨域读取阻止(CORB)引起的。因此,在您的情况下,使用webContentLink代替怎么样webViewLink就像下面的URL。

https://drive.google.com/uc?id=xxxxxxxxxxx5mLv9lYob&export=download

修改HTML后,它如下所示。

修改后的HTML:

<!DOCTYPE html>
<html>
<body>

<video width="320" height="240" controls>
  <source src="https://drive.google.com/uc?id=xxxxxxxxxxx5mLv9lYob&export=download" type="video/mp4">
</video>

</body>
</html>

注意:

  • 在这种情况下,视频文件需要共享。请注意这一点。

参考:

如果这不能解决您的问题,我深表歉意。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

使用Google Drive API在指定的Google Drive中上传文件

如何使用Google Drive API上传文件?

如何使用PHP获取在Google Drive SDK中上传的文件URL

示例不是用于在 google drive API 中上传文件的请求原始正文的格式

获取/生成Google Drive API v3中上传文件的共享链接

使用Drive API将图片上传到Google Drive

如何使用Google Drive API将文件上传到Google Drive?

如何使用PHP Google Drive API在Google Drive上上传文件

如何使用python google drive api将文件夹上传到共享的google drive?

如何使用 Google Drive API 上传我的 Drive (PHP) 中的文件?

文件上传到 Google Drive

如何使用 gdrive 将文件上传到 Google Drive 目录?

Google Drive PHP API空上传的文件

Google Drive API上传格式无效?

使用Google Drive API上传PDF文件-Google Drive Web Client中没有预览

使用 api 获取 Google Drive 视频嵌入代码

如何使用PyDrive访问Team Drive而不是个人Google Drive?

使用Google Drive API与特定用户共享上传的文件

使用Google Drive API上传文件夹中的文件

使用 Google Drive API 时不显示上传的文件

在C#中使用Google Drive Api上传的图像出错

使用Google Drive Api上传图像文件

使用Javascript在Youtube APi中上传视频

Google Drive API:如何从Google Drive下载文件?

如何在Google Colab中处理来自Google Drive的视频

Google Drive Rest API

如何使用 Google Drive API V3 将文件上传到 Group Drive(共享驱动器)?

使用Google Drive API以编程方式登录到Google Drive

使用Google Drive API从Google Drive直接下载