2

I'm using google drive javascript api(v2) in my reactjs project. And I'm using this function to get files from google drive.

this.getProjectObjects = function(query, callback)
{
    var request = gapi.client.drive.files.list({
        corpus : 'DEFAULT',
        q : query,
        fields : 'items(id,description,title,properties)'
    });

    request.then(function(resp) {
        callback(resp.result.items)
    }, function(err) {
        console.log(err)
    });
};

After authenticate the user, I can get the files using this function. But, when I navigate to other react component, it's no longer working. There is no response or error, api just hangs.

Silly thing is when I refresh page, it's working. Again if I navigate to other component, it's not working.

I'm using the same query, nothing changed during navigating.

Anyone have any ideas what the issue could be?

Thanks

Bill Kim
  • 31
  • 1
  • Hi Bill, can you see if a network request is sent after the call using the devtools? What action does 'navigating to another component' confer? Is that loading a new page, or an internal navigation that does not reload the browser? In the past I've had issues using the 'fields' param. You may consider trying it without specifying and see if that helps. – Grant Watters Feb 01 '17 at 03:33
  • Hi Grant, the app doesn't reload the page since it's SPA. but if I reload it's working and I can see the request being sent from dev console. But after navigate to other page, I can't see the network request. – Bill Kim Feb 01 '17 at 10:40
  • Also, it was working before(2~3 months ago) but it's not working anymore. and there was no code change. – Bill Kim Feb 01 '17 at 10:54

1 Answers1

0

You may want to check the Chrome devTools to see if you are encountering any problem when switching pages. Also in the documentation - Getting Started:

There are several ways to use the JavaScript client library to make API requests, but they all follow the same basic pattern:

  • The application loads the JavaScript client library.
  • The application initializes the library with API key, OAuth client ID, and API Discovery Document(s).
  • The application sends a request and processes the response.

The following sections show 3 common ways of using the JavaScript client library.

  • Option 1: Load the API discovery document, then assemble the request.
  • Option 2: Use gapi.client.request
  • Option 3: Use CORS

See the sample for code implementation on effectively loading and making API calls.

Hope this helps.

Mr.Rebot
  • 6,703
  • 2
  • 16
  • 91