title: google drive javascript api TypeError: Cannot read property 'drive' of undefined in gapi.client.drive.files Angular 4 Ionic 2
body: <p>I am working with Angular 4/Ionic 2 and have followed javascript Google Drive documentation <a href="https://developers.google.com/drive/v3/web/quickstart/js" rel="nofollow noreferrer">https://developers.google.com/drive/v3/web/quickstart/js</a> to list google drive files but i am getting error (ERROR TypeError: Cannot read property 'drive' of undefined).</p>
  
  <p>I have also followed this question <a href="https://stackoverflow.com/questions/15589794/call-gapi-client-load-before-all-my-executions-correct">Call gapi.client.load(...) Before all my executions correct?</a> On implementing this i get an error that (load is undefined).</p>
  
  <p>While following this question <a href="https://stackoverflow.com/questions/11315962/google-drive-api-javascript">Google Drive API javascript</a> I have implemented its 1st answer and get an error on </p>
  
  <pre><code>var request = gapi.client.request({
          'path': '/drive/v2/files',
          'method': 'GET',
          'params': {'maxResults': '1'}
          });
  </code></pre>
  
  <p>gapi.client.request is undefined.</p>
  
  <p>Currently my function of getting files from google drive is</p>
  
  <pre><code> listFile() {
          var request = gapi.client.drive.files.list({
              'pageSize': 10,
              'fields': "nextPageToken, files(id, name)"
            });
  
            request.execute(function(resp) {
              this.appendPre('Files:');
              var files = resp.files;
              if (files &amp;&amp; files.length &gt; 0) {
                for (var i = 0; i &lt; files.length; i++) {
                  var file = files[i];
                  this.appendPre(file.name + ' (' + file.id + ')');
                }
              } else {
                this.appendPre('No files found.');
              }
            });
    } 
  </code></pre>
  
  <p>The tutorial i completely followed is <a href="https://stackoverflow.com/questions/39907913/google-drive-api-in-angular2-ionic2-gapi-client-drive">Google Drive API in Angular2/Ionic2 gapi.client.drive</a> </p>
  
  <p>I have implemented all of the above solutions but they are not working in my case. Anyone help will be appreciated. Thank you</p>