有人能帮我知道如何获得这些链接授权吗?
使用服务帐户凭据创建驱动器服务与oauth2几乎相同。
var service = AuthenticationHelper.AuthenticateServiceAccount("1046123799103-6v9cj8jbub068jgmss54m9gkuk4q2qu8@developer.gserviceaccount.com",@"C:\Users\HPUser\Downloads\e8bf61cc9963.p12");
/// <summary>
/// Authenticating to Google using a Service account
/// Documentation: https://developers.google.com/accounts/docs/OAuth2#serviceaccount
/// </summary>
/// <param name="serviceAccountEmail">From Google Developer console https://console.developers.google.com</param>
/// <param name="keyFilePath">Location of the Service account key file downloaded from Google Developer console https://console.developers.google.com</param>
/// <returns></returns>
public static DriveService AuthenticateServiceAccount(string serviceAccountEmail, string keyFilePath)
{
// check the file exists
if (!File.Exists(keyFilePath))
{
Console.WriteLine("An Error occurred - Key file does not exist");
return null;
}
string[] scopes = new string[] { DriveService.Scope.Drive }; // View analytics data
var certificate = new X509Certificate2(keyFilePath, "notasecret", X509KeyStorageFlags.Exportable);
try
{
ServiceAccountCredential credential = new ServiceAccountCredential(
new ServiceAccountCredential.Initializer(serviceAccountEmail)
{
Scopes = scopes
}.FromCertificate(certificate));
// Create the service.
DriveService service = new DriveService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "Drive API Sample",
});
return service;
}
catch (Exception ex)
{
Console.WriteLine(ex.InnerException);
return null;
}
上述方法将返回一个驱动器服务,您可以使用该服务进行任何其他调用。这是我用来下载文件的方法。一旦从files.list中取回fileresource
var m = service.Files.List().Execute();
如您所见,它使用downloadURL下载文件。
/// <summary>
/// Download a file
/// Documentation: https://developers.google.com/drive/v2/reference/files/get
/// </summary>
/// <param name="_service">a Valid authenticated DriveService</param>
/// <param name="_fileResource">File resource of the file to download</param>
/// <param name="_saveTo">location of where to save the file including the file name to save it as.</param>
/// <returns></returns>
public static Boolean downloadFile(DriveService _service, File _fileResource, string _saveTo)
{
if (!String.IsNullOrEmpty(_fileResource.DownloadUrl))
{
try
{
var x = _service.HttpClient.GetByteArrayAsync(_fileResource.DownloadUrl );
byte[] arrBytes = x.Result;
System.IO.File.WriteAllBytes(_saveTo, arrBytes);
return true;
}
catch (Exception e)
{
Console.WriteLine("An error occurred: " + e.Message);
return false;
}
}
else
{
// The file doesn't have any content stored on Drive.
return false;
}
}
我遵循了这个基本教程,但我得到: 什么应该包含重定向URI?
我们还需要能够生成直接链接到他们的照片,视频等。 我们已经成功地以这种方式与Dropbox集成,并希望提供谷歌驱动器作为替代方案。这些场景在Google Drive上可能吗?
我正在尝试Google Drive API V3。 拥有一些共享驱动器文件夹的访问权限,并且是所有这些资源的管理员,我想获取一个通过查询筛选的特定文件夹。 出于任何原因,当我尝试按照留档建议插入查询时,它会响应一个错误,这个错误不是很描述性,也不利于调试: 此外,如果我不带条件地执行查询,则响应会成功,并显示整个共享驱动器: 有什么帮助吗? 谢谢
我尝试的是下面的,但不是工作 从谷歌REST链接,它显示的例子如下,如何运行这个?
我收到以下例外情况: 调用修补程序https://www.googleapis.com/upload/drive/v3/files/abcde4fghvxztkvoskvetjktne0?uploadtype=multipart:(403)资源正文包含不可直接写入的字段。
我需要一些关于谷歌硬盘C#示例程序的帮助。。。 我使用了这个所谓的“教程”/“示例”: https://developers.google.com/drive/examples/dotnet 这里的代码是: https://code.google.com/p/google-drive-sdk-samples/source/checkout 我在这里上传了我的(只是稍微修改过的)源代码,以防任何人没