Google Drive .NET SDK版本3-共享链接 [英] Google Drive .NET SDK version 3 - shareable links

查看:183
本文介绍了Google Drive .NET SDK版本3-共享链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个mp4视频文件,该文件位于Google云端硬盘的视频"文件夹中.我想使用C#sdk v3获得指向此文件的可共享链接.在我的代码中,我设置了文件(和文件夹)的权限:

I have an mp4 video file that sits in the "Videos" folder in Google Drive. I want to get a shareable link to this file using C# sdk v3. In my code I set permissions for the file (and the folder):

string fileId = "..real..file..id..here.."
Google.Apis.Drive.v3.Data.Permission permission = new Google.Apis.Drive.v3.Data.Permission();
permission.Type = "anyone";
permission.Role = "reader";
permission.AllowFileDiscovery = true;

PermissionsResource.CreateRequest request = _service.Permissions.Create(permission, fileId);
request.Fields = "id";
request.Execute();

_service变量是DriveService对象.我可以看到该文件(和文件夹)的权限设置正确.然后,我尝试使用以下代码获取链接:

_service variable is a DriveService object. I can see that permissions are set correctly for the file (and for the folder). Then I try to get the link with the following code:

 FilesResource.ListRequest listRequest = _service.Files.List();
 List<Google.Apis.Drive.v3.Data.File> files = listRequest.Execute().Files.ToList();
 Google.Apis.Drive.v3.Data.File myVideo = files.Single(f => f.Id == fileId);
 string shareableLink = myVideo.WebContentLink;

文件"myVideo"已正确检索,但是WebContentLink属性为null.我在这里想念什么?

File "myVideo" is retrieved correctly, however, the WebContentLink property is null. What am I missing here?

更新: AllowFileDiscovery = false;没什么区别.

Update: AllowFileDiscovery = false; doesn't make any difference.

更新:设置权限后,您可以使用文件ID: https://drive.google.com/uc?id=..file..id..goes ..此处

Update: After permissions are set you can construct the url manually with the file id: https://drive.google.com/uc?id=..file..id..goes..here

推荐答案

这是一个非常老的问题,没有答案.我遇到了类似的难题,即webcontentlink结果为NULL.解决方案是,您需要将"webContentLink"放入请求的fields属性中,如下所示.

This is very old question with no answer. I faced similar dilemma i.e. webcontentlink in result was coming as NULL. The solution is that you need to put "webContentLink" in request's fields property as shown below.

listRequest.Fields = "id, webContentLink";

这篇关于Google Drive .NET SDK版本3-共享链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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