在https://developers.google.com/drive/v3/web/migration下,我发现GDrive v2 API的about部分中的QuotaBytesTotal已更改为storageQuota.limit。 QuotaBytesUsed已更改为storageQuota.usageInDrive。任何人都可以举例说明如何在GApis.v3中调用它吗?
我使用的旧代码(Google Apis v2)如下:
private long GetQuotaTotal(Google.Apis.Drive.v3.DriveService service)
{
var quotaBytesTotal = service.About.Get().Execute().QuotaBytesTotal;
if (quotaBytesTotal == null)
return 0;
return (long) quotaBytesTotal;
}
对于QuotaBytesUsed完全相同的事情:
private long GetQuotaUsed(Google.Apis.Drive.v3.DriveService service)
{
var quotaBytesUsed = service.About.Get().Execute().QuotaBytesUsed;
if (quotaBytesUsed == null)
return 0;
return (long) quotaBytesUsed;
}
答案 0 :(得分:2)
我认为这就是你想要的:
public long GetDriveSpaceUsage()
{
try
{
AboutResource.GetRequest ag = new AboutResource.GetRequest(_CurrentDriveService);
ag.Fields = "user,storageQuota";
var response = ag.Execute();
if (response.StorageQuota.Usage.HasValue)
{
return response.StorageQuota.Usage.Value;
}
else
{
return -1;
}
}
catch (Exception e)
{
System.Diagnostics.Debug.WriteLine(e.Message);
return -1;
}
}
public long GetDriveSpaceLimit()
{
try
{
AboutResource.GetRequest ag = new AboutResource.GetRequest(_CurrentDriveService);
ag.Fields = "user,storageQuota";
var response = ag.Execute();
if (response.StorageQuota.Limit.HasValue)
{
return response.StorageQuota.Limit.Value;
}
else
{
return -1;
}
}
catch (Exception e)
{
System.Diagnostics.Debug.WriteLine(e.Message);
return -1;
}
}