title: Upload file to Google drive using cron executed PHP
body: <p>I'm trying to upload a 50MB file upload to a folder on my Google Drive account.</p>
  
  <p>Algorithm: </p>
  
  <ol>
  <li>Cron triggers PHP - PHP dumps MySQL database and compress and encrypt file;</li>
  <li>Same PHP script triggers another script and supplies file name. This script should use Google Drive API to upload the file to my Google Drive account.</li>
  </ol>
  
  <p>Then file should be available on my Google Drive as <code>blahblahblah/backup.sql.tar.gz</code></p>
  
  <p>But it isn't. And I'm sure that everything fails on part where upload is ended - no output.</p>
  
  <p>I don't even know how the hell I'm supposed to get client secret? I tried dev console but I only get:</p>
  
  <pre><code>CLIENT ID
  CERTIFICATE FINGERPRINTS
  API KEY
  </code></pre>
  
  <p>I have tried so far:</p>
  
  <p><a href="https://developers.google.com/drive/web/quickstart/quickstart-php" rel="nofollow">https://developers.google.com/drive/web/quickstart/quickstart-php</a>
  <a href="https://github.com/google/google-api-php-client/tree/master/examples" rel="nofollow">https://github.com/google/google-api-php-client/tree/master/examples</a></p>
  
  <p>And also this:</p>
  
  <pre><code>&lt;?PHP
  /**
   * Insert new file.
   *
   * @param Google_DriveService $service Drive API service instance.
   * @param string $title Title of the file to insert, including the extension.
   * @param string $description Description of the file to insert.
   * @param string $parentId Parent folder's ID.
   * @param string $mimeType MIME type of the file to insert.
   * @param string $filename Filename of the file to insert.
   * @return Google_DriveFile The file that was inserted. NULL is returned if an API error occurred.
   */
  function insertFile($service, $title, $description, $parentId, $mimeType, $filename) {
    $file = new Google_DriveFile();
    $file-&gt;setTitle($title);
    $file-&gt;setDescription($description);
    $file-&gt;setMimeType($mimeType);
  
    // Set the parent folder.
    if ($parentId != null) {
      $parent = new Google_ParentReference();
      $parent-&gt;setId($parentId);
      $file-&gt;setParents(array($parent));
    }
  
    try {
      $data = file_get_contents($filename);
  
      $createdFile = $service-&gt;files-&gt;insert($file, array(
        'data' =&gt; $data,
        'mimeType' =&gt; $mimeType,
        'uploadType' =&gt; 'media'
      ));
  
      // Uncomment the following line to print the File ID
      // print 'File ID: %s' % $createdFile-&gt;getId();
  
      return $createdFile;
    } catch (Exception $e) {
      print "An error occurred: " . $e-&gt;getMessage();
    }
  }
  </code></pre>
  
  <p>I use the latest Google API PHP Client Library.</p>
  
  <p>Can I get simple PHP code which will work out of the box utilizing the API and uploading the file?</p>
  
  <p>There are no user actions involved. I do not need to authorize user. 
  Everything should be done on server side.</p>