Mike
Mike

Reputation: 31

Google Drive API v3 change list request returns 400 bad request using .NET client

We are creating a .NET app that will capture Google Drive changes and we are using the .NET client for the Google Drive V3 API. The code below shows how we are calling the Changes.List method to return a list of drive changes. This code worked a couple of days ago but now every time it just returns error code 400 (Bad Request). Is anyone else seeing an issue?

        var credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
            Secrets,
            Scopes,
            "user",
            CancellationToken.None,
            dataStore).Result;

        // Create Drive API service.
        var service = new DriveService(new BaseClientService.Initializer() { 
            HttpClientInitializer = credential,
            ApplicationName = ApplicationName,
        });

        while (pageToken != null)
        {
            var changeListRequest = service.Changes.List(pageToken);
            changeListRequest.Fields = "*";

            changeList = changeListRequest.Execute();

            pageToken = changeList.NextPageToken;
        }

The error occurs on the changeListRequest.Execute() call.

Upvotes: 1

Views: 1579

Answers (2)

Mike
Mike

Reputation: 31

OK, so I found out the problem was the line:

changeListRequest.Fields = "*". 

Instead of the asterisk, I had to specify the actual fields:

changeListRequest.Fields = "changes,kind,newStartPageToken,nextPageToken";

Now it seems to work fine. The thing is my old code worked fine until a couple of days ago! In fact, I copied the code from Google's .NET example which used the asterisk. I'm glad this wasn't production code.

Upvotes: 2

abielita
abielita

Reputation: 13469

Based from this Handling API Errors documentation, the 400 Bad Request error means that the request you sent to the website server, often something simple like a request to load a webpage, was somehow incorrect or corrupted and so the server couldn't understand it.

This code worked a couple of days ago but now every time it just returns error code 400 (Bad Request).

  • Clear your browser's cookies and cache, especially you're getting a Bad Request error with a Google service. Many sites have reported a 400 error when a cookie that it's reading is corrupt or too old.

You can also check this similar issue Getting 200 OK abd 400 bad request on the same request from Google Drive REST API.

Upvotes: 0

Related Questions