簡體   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