Call gapi.client.load(…) Before all my executions

2019-02-14 08:31发布

问题:

I'm not sure if I'm understanding this correctly, do I need to create a function like this:

function execute(callback) {
    gapi.client.load('drive', 'v2', function() {
      callback();
    });
}

And then for all my calls call it like this?

function retrieveAllFiles() {
    execute(function(){
      var request = gapi.client.drive.files.list();
      request.execute(function(resp) { 
          console.log(resp);
      }
    }
}

function deletefile() {
    execute(function(){ 
    ...

It works fine but I'm not sure if this is the correct way of doing it?

回答1:

Yes, that is probably the easiest way to do it. It is certainly an acceptable way.