hreinn1000
hreinn1000

Reputation: 255

Selecting specific fields with Google Drive Api v2

I have an error,

Google.Apis.Requests.RequestErrorInvalid field selection filesize [400]Errors [Message[Invalid field selection filesize] Location[fields - parameter] 

When I call request.Fields = "items(id,title,filesize)"; this works fine: request.Fields = "items(id,title)";

in this context,

DriveService service = new DriveService(new BaseClientService.Initializer()
{
    HttpClientInitializer = credential,
    ApplicationName = "Drive API Sample",
});

FilesResource.ListRequest request = service.Files.List();
request.MaxResults = 100;
request.Q = string.Format("(title contains '{0}') and (mimeType contains 'image/')",filename);
request.Fields = "items(id,title)";

If I dump out the item result, it does indeed contain a filesize column, not always, for folders and some other it's null.

Anyone ran into this ? My googlefu doesn't really turn anything up...

Upvotes: 3

Views: 2968

Answers (3)

Josh Houghton
Josh Houghton

Reputation: 49

Sorry if this is slightly off topic but for the benefit of anybody who wants to get one file rather than list them all (in the V3 C#/.NET package), and cannot tolerate the lack of helpfulness of Google's documentation, input the fields like so..

var req = DriveApi.Files.Get(fileId);
req.Fields = "id,size,name,etc..."; 

If you need to know the field names, lookup the definition of the properties of the response object

var res = req.Execute();
res.Size <-- Right click and 'go to definition'

Look at the property's "JsonPropertyAttribute".

Upvotes: 0

Atihska
Atihska

Reputation: 5126

@hreinn: Though its a very old post, but just for others to have this: In V3, this is size. So listRequest.Fields = "files(id, size)";

Upvotes: 4

hreinn1000
hreinn1000

Reputation: 255

Ok, decided to do some more google fu, seems like it failed before. But I'll leave this here for the next me.

"items(fileSize,id)"; , so it seems it had to be case sensitive, I'd tried the c# class dump, and the field is called FileSize there, that didn't work.

At the bottom of this page,

https://developers.google.com/drive/v2/reference/files/list

Upvotes: 0

Related Questions