title: Uploading files to Google Drive
body: <p>I am trying to upload files from my PHP-based website to Google Drive. I searched, got google-api-php-client library. In documentation an example is given but that can be run on php shell (Command line). I tried to run that example in browser, I got error of curl extention, and fixed that.</p>
  
  <p>Now I am getting error related to authenticating code to allow access. I do not need authentication at all in my project, but for the time being I can try with it.  </p>
  
  <p>I have the following code in <code>www.mydomain.com/drive/index.php</code> file:</p>
  
  <pre><code>    &lt;?php
      require_once 'google-api-php-client/src/Google_Client.php';
      require_once 'google-api-php-client/src/contrib/Google_DriveService.php';
  
      $client = new Google_Client();
      // Get your credentials from the APIs Console
      $client-&gt;setClientId('MY-CLIENT-ID');
      $client-&gt;setClientSecret('MY-CLIENT-SECRET');
      $client-&gt;setRedirectUri('http://www.MY-DOMAIN.com/drive/auth.php');
      //AUTH.PHP should have code to authenticate code and return back another code.
      $client-&gt;setScopes(array('https://www.googleapis.com/auth/drive'));
  
      $service = new Google_DriveService($client);
  
  //**********************authentication process for SHELL
  //I want this authentication process to remove at all or convert to web based authentication        
  
      $authUrl = $client-&gt;createAuthUrl();
  
      //Request authorization
      print "Please visit:\n$authUrl\n\n";
      print "Please enter the auth code:\n";
  
  
      $authCode = trim(fgets(STDIN));
  
      // Exchange authorization code for access token
      $accessToken = $client-&gt;authenticate($authCode);
      $client-&gt;setAccessToken($accessToken);
  //************************************************************
      //Insert a file
      $file = new Google_DriveFile();
      $file-&gt;setTitle('My document');
      $file-&gt;setDescription('A test document');
      $file-&gt;setMimeType('text/plain');
  
      $data = file_get_contents('document.txt');
  
      $createdFile = $service-&gt;files-&gt;insert($file, array(
            'data' =&gt; $data,
            'mimeType' =&gt; 'text/plain',
          ));
  
      print_r($createdFile);
      ?&gt;
  </code></pre>
  
  <p>Can I upload file without authentication need for each upload? If yes then how? If no then how to authenticate?</p>