title: Google Drive API Domain Wide Delegation of Authority - PHP instantiate a drive service object errors
body: <p>I have been trying to implement a program that uploads backups of my user's websites to google drive. All of them have an account on my domain, so I went through the steps of granting domain wde delegation of authority for my app as described here: <a href="https://developers.google.com/drive/delegation" rel="nofollow">https://developers.google.com/drive/delegation</a></p>
  
  <p>Unfortunately their sample code to instantiate a drive service object fails on many levels. Here it is:</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";
  require_once "google-api-php-client/src/contrib/Google_Oauth2Service.php";
  session_start();
  
  $DRIVE_SCOPE = 'https://www.googleapis.com/auth/drive';
  $SERVICE_ACCOUNT_EMAIL = '&lt;some-id&gt;@developer.gserviceaccount.com';
  $SERVICE_ACCOUNT_PKCS12_FILE_PATH = 'privatekey.p12';
  
  /**
   * Build and returns a Drive service object 
   * authorized with the service accounts
   * that acts on behalf of the given user.
   *
   * @param userEmail The email of the user.
   * @return Google_DriveService service object.
   */
  function buildService($userEmail) {
    $key = file_get_contents(KEY_FILE);
    $auth = new Google_AssertionCredentials(
        SERVICE_ACCOUNT_EMAIL,
        array(DRIVE_SCOPE),
        $key);
    $auth-&gt;setPrn($userEmail);
    $client = new Google_Client();
    $client-&gt;setUseObjects(true);
    $client-&gt;setAssertionCredentials($auth);
    return new Google_DriveService($client);
  }
  
  ?&gt;
  </code></pre>
  
  <p>The first obvious error is they have you set up variables but then the function uses constants. So I hardcoded in what should be there for the constants (KEY_FILE, SERVICE_ACCOUNT_EMAIL, etc) just to see if it worked and then I get the following error:</p>
  
  <pre><code>Fatal error: Call to undefined method Google_AssertionCredentials::setPrn()
  </code></pre>
  
  <p>Does anyone have any suggestions or comments on how to fix this? If you google these issues, google just gives page after page of links to their own documentation, which as I show above, does not work at all.</p>
  
  <p>Basically I was hoping to see an example of how to use a "service account" which has been granted domain wide access to instantiate a drive service object.</p>