2017-08-15 129 views
0

我想要与指定用户共享Google云端硬盘中存在的文件。该文件不公开。与Google云端硬盘中的指定用户共享文档

首先,我想在WebBrowser控件中显示一个文件。 其次,我希望当我将某个网址分享给其他用户时,他们可以在其Google云端硬盘中显示该文件。

这是我的代码,我已经可以做第一步,但对于第二步,我不知道我该怎么做。

Public Sub A(fichier As String) 
CreateService() 
    Dim url As String = "" 
    Dim list = Service.Files.List() 
    Dim count = list.Execute() 
    For Each fich In count.Items 
     If (fich.Title) = fichier Then 
      url = fich.WebContentLink 
      Exit For 
     End If 
    Next 
    affich_image.img.Navigate(url) 
    affich_image.Show() 

回答

1

您可以使用permissions.insert方法。

插入文件或团队云端硬盘的权限。

要查看参数和更多详细信息,请尝试访问documentation

在这里,我为您提供了上述文档中介绍的.NET的示例代码。

using Google.Apis.Drive.v2; 
using Google.Apis.Drive.v2.Data; 

using System.Net; 
// ... 

public class MyClass { 

    // ... 

    /// <summary> 
    /// Insert a new permission. 
    /// </summary> 
    /// <param name="service">Drive API service instance.</param> 
    /// <param name="fileId">ID of the file to insert permission for.</param> 
    /// <param name="value"> 
    /// User or group e-mail address, domain name or null for "default" type. 
    /// </param> 
    /// <param name="type">The value "user", "group", "domain" or "default".</param> 
    /// <param name="role">The value "owner", "writer" or "reader".</param> 
    /// <returns>The inserted permission, null is returned if an API error occurred</returns> 
    public static Permission InsertPermission(DriveService service, String fileId, String value, 
     String type, String role) { 
    Permission newPermission = new Permission(); 
    newPermission.Value = value; 
    newPermission.Type = type; 
    newPermission.Role = role; 
    try { 
     return service.Permissions.Insert(newPermission, fileId).Execute(); 
    } catch (Exception e) { 
     Console.WriteLine("An error occurred: " + e.Message); 
    } 
    return null; 
    } 

    // ... 

} 

您也可以访问此SO post作进一步讨论。

相关问题