Riddari
Riddari

Reputation: 1773

Google Drive API bad request from C# but fine from Postman

I'm using this request code from C# and getting a Bad Request result:

    public class GoogleDriveManager
    {
        private static readonly HttpClient Client = new HttpClient();
        private const string Access = "ACCESS";

        public GoogleDriveManager()
        {
            Client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Access);
        }

        public async Task<HttpResponseMessage> GetFilesAsync(string driveId)
        {
            var url =
                $"https://www.googleapis.com/drive/v3/files?driveId={driveId}&includeItemsFromAllDrives=true&corpora=true&supportsAllDrives=true";
            var result = await Client.GetAsync(url);
            return result;
        }
   }

But when I make the same sort of request from Postman, it works great:

GET https://www.googleapis.com/drive/v3/files?driveId=DRIVEID&includeItemsFromAllDrives=true&corpora=drive&supportsAllDrives=true

(Authorization Bearer Token, with token value the same as the one used above)

What am I doing wrong on the C# side?

Upvotes: 1

Views: 90

Answers (1)

emt
emt

Reputation: 77

According to API documentation supported values for corpora are:

  • user
  • domain
  • drive
  • allDrives

Your Postman example has corpora=drive but your C# example shows corpora=true.

Upvotes: 2

Related Questions