title: PHP Google Drive API installation and file upload
body: <p>Hi guys i'm trying uploading file trought G drive API.</p>
  
  <p>Can't find out why it returns error:</p>
  
  <pre><code>&lt;?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  
  class Gdrive{
  
  function initialize(){
  $credentials = $this-&gt;GetOAuth2Credentials($_GET['code']);
  $_SESSION['credentials'] = $credentials;
  
  }
  /**
   * Exchange an authorization code for OAuth 2.0 credentials.
   *
   * @param String $authorizationCode Authorization code to exchange for an
   *     access token and refresh token.  The refresh token is only returned by
   *     Google on the very first exchange- when a user explicitly approves
   *     the authorization request.
   * @return OauthCredentials OAuth 2.0 credentials object
   */
  function GetOAuth2Credentials($authorizationCode) {
    $client = new apiClient();
    $client-&gt;setClientId(Config::5112+++++.apps.****5971157@developer.gserviceaccount.com);
    $client-&gt;setRedirectUri(Config::site_url());
  
    /**
     * Ordinarily we wouldn't set the $_GET variable.  However, the API library's
     * authenticate() function looks for authorization code in the query string,
     * so we want to make sure it is set to the correct value passed into the
     * function arguments.
     */
    $_GET['code'] = $authorizationCode;
  
    $jsonCredentials = json_decode($client-&gt;authenticate());
  
    $oauthCredentials = new OauthCredentials(
        $jsonCredentials-&gt;access_token,
        isset($jsonCredentials-&gt;refresh_token)?($jsonCredentials-&gt;refresh_token):null,
        $jsonCredentials-&gt;created,
        $jsonCredentials-&gt;expires_in,
        Config::CLIENT_ID,
        Config::CLIENT_SECRET
    );
  
    return $oauthCredentials;
  }
  function SaveNewFile($inputFile) {
    try {
      $mimeType = 'text/plain';
      $file = new Google_DriveFile();
      $file-&gt;setTitle($inputFile-&gt;title);
      $file-&gt;setDescription($inputFile-&gt;description);
      $file-&gt;setMimeType($mimeType);
      // Set the parent folder.
      if ($inputFile-&gt;parentId != null) {
        $parentsCollectionData = new DriveFileParentsCollection();
        $parentsCollectionData-&gt;setId($inputFile-&gt;parentId);
        $file-&gt;setParentsCollection(array($parentsCollectionData));
      }
      $createdFile = $this-&gt;service-&gt;files-&gt;insert($file, array(
          'data' =&gt; $inputFile-&gt;content,
          'mimeType' =&gt; $mimeType,
      ));
      return $createdFile;
    } catch (apiServiceException $e) {
      /*
       * Log error and re-throw
       */
      error_log('Error saving new file to Drive: ' . $e-&gt;getMessage(), 0);
      throw $e;
    }
  }
  
  
  }
  </code></pre>
  
  <p>when i invoke the initialize() method it returns error:</p>
  
  <pre><code>Message: Undefined index: code
  
  Fatal error: Class 'apiClient' not found
  </code></pre>
  
  <p>what should be? i'm doing right in my code ? does i need more code to make it works? i created web application project on google api console.</p>
  
  <p>need i to include google php sdk? in the google docs it is not mentioned for google drive api :/</p>