在Google云端硬盘中与指定用户共享文档

时间:2017-08-15 12:38:15

标签: vb.net google-drive-api

我想与指定用户共享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 个答案:

答案 0 :(得分: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进行进一步讨论。