使用来自c#的Google Drive API和Spreadsheet Api。
如何将文件夹和文件(速查表)添加到文件夹,并确保它们始终对人类用户是共享和可见的?
我知道Google.Apis.Drive.Permission,但它有每日配额,并发送电子邮件,这似乎不是正确的解决方案。
我更希望能够在文件夹中工作,然后所有内容都应该始终对API和人类用户可见。
任何提示:)
发布于 2019-09-03 20:06:55
您可以使用Google drive api创建一个文件,然后添加对该文件的权限,以便与用户共享该文件。这就是你怎么做的,真的没有比这更好的方法了。为了使用户能够访问它,您必须授予他们对它的权限。
/// <summary>
/// Creates a permission for a file or Team Drive.
/// Documentation https://developers.google.com/drive/v3/reference/permissions/create
/// Generation Note: This does not always build corectly. Google needs to standardise things I need to figuer out which ones are wrong.
/// </summary>
/// <param name="service">Authenticated Drive service.</param>
/// <param name="fileId">The ID of the file or Team Drive.</param>
/// <param name="body">A valid Drive v3 body.</param>
/// <param name="optional">Optional paramaters.</param>
/// <returns>PermissionResponse</returns>
public static Permission Create(DriveService service, string fileId, Permission body, PermissionsCreateOptionalParms optional = null)
{
try
{
// Initial validation.
if (service == null)
throw new ArgumentNullException("service");
if (body == null)
throw new ArgumentNullException("body");
if (fileId == null)
throw new ArgumentNullException(fileId);
// Building the initial request.
var request = service.Permissions.Create(body, fileId);
// Applying optional parameters to the request.
request = (PermissionsResource.CreateRequest)SampleHelpers.ApplyOptionalParms(request, optional);
// Requesting data.
return request.Execute();
}
catch (Exception ex)
{
throw new Exception("Request Permissions.Create failed.", ex);
}
}从我的示例项目PermissionsSample.cs中摘录的代码
如果你在配额上有问题,那么你可以尝试去谷歌开发者控制台,让你的配额增加。注意:配额是基于请求的数量,而不是您正在发出的请求的类型。
发布于 2019-09-05 20:37:30
感谢您提供的有关权限的信息和示例!
我发现,如果你只是手动创建一个文件夹,这个文件夹是用google-drive-API-email-address共享的读/写的,然后确保这个文件夹中的所有东西都在运行,它的行为是想要的,所有文件对人和计算机都是可见的。
向Anders致以最好的问候
https://stackoverflow.com/questions/57771183
复制相似问题