0
votes

I am trying to search Google Drive for Excel files using the Javascript API (v3). Some Excel files seem to have a mime type of 'application/vnd.ms-excel' and some have a mime type of 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'.

When I use mime type 'application/vnd.ms-excel', the files with that mime type are returned correctly. But, when I use the mime type 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' I get a ton of irrelevant results (with mime types like 'x-javascript', 'x-markdown', and even 'image/png').

Is this a bug or am I doing something wrong?
Any help will be greatly appreciated! Thanks.

Here's my code:

function getItemsByQuery(query, callback) {

    var retrievePageOfFiles = function(request, result) {
        request.execute(function(resp) {
            result = result.concat(resp.files);
            var nextPageToken = resp.nextPageToken;
            if (nextPageToken) {
                request = gapi.client.drive.files.list({ 'pageToken': nextPageToken });
                retrievePageOfFiles(request, result);
            }
            else {
                result.length > 0 ? callback(result) : callback([]);
            }
        });
    };

    var q = {'q': query };
    var initialRequest = gapi.client.drive.files.list(q);
    retrievePageOfFiles(initialRequest, []);
}

getItemsByQuery("trashed=false and mimeType='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'", function(results) {
    // Handle results - lots of irrelevant files returned here.
});
1
Can you show us what the response body looks like where the supposedly irrelevant results are included?abielita
@abielita I would gladly provide whatever is needed, I'm just not sure what you are asking me to provide. What is it you need me to show you exactly?DataGrump
I think @abielita is referring to your statement "But, when I use the mime type 'application/vnd.openxmlformats-officedocument.spreadsheetml‌​.sheet' I get a ton of irrelevant results (with mime types like 'x-javascript', 'x-markdown', and even 'image/png')". abielita wants you to show that response in its raw format to figure out if it's really irrelevant.noogui
@abielita I simply receive an array of objects from the Javascript API. See some examples here: link. Is this what you mean by "raw data"?DataGrump

1 Answers

1
votes

It looks like you forgot to add the q field when rebuilding the query with a pageToken field.