简体   繁体   English

如何使用适用于Windows Phone 8.1的Google Drive API V2共享任何文件

[英]How to share any file using google drive api v2 for Windows Phone 8.1

I am using Google.Apis.Drive.v2 for dotnet. 我正在将Google.Apis.Drive.v2用于dotnet。

I am trying to integrate google drive in my own Windows Phone 8.1 app, but i am not able to get a share link for a file which can be used by anyone to download that file. 我正在尝试将Google驱动器集成到我自己的Windows Phone 8.1应用中,但是我无法获得文件的共享链接,任何人都可以使用该链接下载该文件。 Any kind of help is appreciated. 任何帮助都将受到赞赏。

Auth code: 授权码:

if (service != null) return; 

credential = await GoogleWebAuthorizationBroker.AuthorizeAsync( 
         new Uri("ms-appx:///Assets/client_secret.json"), 
         new[] { DriveService.Scope.Drive },
         "user",
         CancellationToken.None); 
var initializer = new BaseClientService.Initializer() {  
     HttpClientInitializer = credential, }; 

service = new DriveService(initializer); 
service.HttpClient.Timeout = new TimeSpan(1, 0, 0); 
}  

request: 请求:

var list = DriveService.Files.List(); 
foreach (var item in list.Items) { 
  string sharingLink = item.WebContentLink; } 

Thanks. 谢谢。

remember to do execute. 记得要执行。

var result = service.Files.List().Execute();
foreach (var item in result.Items) 
    { 
    string sharingLink = item.WebContentLink; 
    }

Update for comment: 更新评论:

File permissions are a nightmare. 文件权限是一场噩梦。 First update request that you send everything. 第一次更新请求您发送所有内容。 which means if you had the permission Id from the file you could do a permissions get and change what ever you want in that then update that back. 这意味着,如果您具有文件中的权限ID,则可以获取权限并更改其中的所需内容,然后将其更新。 If you just want to change one thing you can use patch along with the permission id from the file. 如果您只想更改一件事,则可以使用patch和文件中的权限ID。

Permission patchedPermission = new Permission();
patchedPermission.Type= anyone;
service.Permissions.Patch(patchedPermission, fileId, permissionId).Execute();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM