繁体   English   中英

将Google Drive Apis v2中使用的QuotaBytesTotal / QuotaBytes迁移到C#.Net中的v3

[英]Migrate QuotaBytesTotal/ QuotaBytesUsed from Google Drive Apis v2 to v3 in C# .Net

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;
}

我认为这是您想要的:

    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;
        }

    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM