AWizardInDallas
AWizardInDallas

Reputation: 119

Error: 'fields' parameter is required for this method

Google API: Google.Apis.Requests.RequestError
The 'fields' parameter is required for this method. [400]
Errors[
Message[The 'fields' parameter is required for this method.] Location[fields - parameter] Reason[required] Domain[global]
]

I'm trying to use the About resource in the Google Drive API (.v3) and receiving an error I can't seem to resolve, that isn't answered in documentation. I've spent a few days researching to no avail and don't quite understand what the error message is telling me. New to using the API. :)

P. S. oRequest.Fields does not exist. Tried that too.

string result = "success";
try {
    About oRequest = driveService.About.Get().Execute();
    result = result + oRequest.User;
} catch (Exception e) {
    result = "Google API: " + e.Message;
}
textBox1.Text = result;
return result;

Updated: The code below is an improvement, but produces "Object reference not set to an instance of an object" on the result line... :\

AboutResource.GetRequest oRequest = driveService.About.Get();
oRequest.Fields = "user:displayName, user:permissionId, user:emailAddress";
About oResponse = oRequest.Execute();
result = oResponse.User.DisplayName + " | " + oResponse.User.PermissionId + " | " + oResponse.User.EmailAddress;

Upvotes: 4

Views: 3759

Answers (2)

ganchito55
ganchito55

Reputation: 3607

You can also request a full User object Google.Apis.Drive.v3.Data.User, if you use "user" as field.

For example:

var request = service.About.Get();
request.Fields = "user";
var user = request.Execute().User;

Instead of getting a full response object Google.Apis.Drive.v3.Data.About

Upvotes: 4

AWizardInDallas
AWizardInDallas

Reputation: 119

Working code:

string result = "success";
try {
    AboutResource.GetRequest oRequest = driveService.About.Get();
    oRequest.Fields = "*";
    About oResponse = oRequest.Execute();
    result = JsonConvert.SerializeObject(oResponse);
} catch (Exception e) {
    result = "Google API: " + e.InnerException;
}
textBox1.Text = result;
return result;

Upvotes: 1

Related Questions