Gmail REST API Example Clarification using PHP -


i'm trying work through php example provided gmail rest api.

i'm not clear information i'm supposed change personal information make example work. i'm self taught , new php info appreciated. i've put comments (mf:) inline changes i've made still not working:

<?php //require 'vendor/autoload.php'; //mf: changed to: require_once('googleapi/src/google/autoload.php');  //mf: downloaded api github  doesn't have "vendor" folder.  //mf: should project name appears in google developers console? matter? define('application_name', 'gmail api quickstart');   //mf: assume download , put path json download file google developer console.  define('credentials_path', '~/.credentials/gmail-api-quickstart.json');   //mf: i'm confused how differs line above. json download has client secret in well. different? define('client_secret_path', 'client_secret.json');   define('scopes', implode(' ', array(   google_service_gmail::gmail_readonly) )); 

//mf: think leave rest alone.

/**  * returns authorized api client.  * @return google_client authorized client object  */ function getclient() {   $client = new google_client();   $client->setapplicationname(application_name);   $client->setscopes(scopes);   $client->setauthconfigfile(client_secret_path);   $client->setaccesstype('offline');    // load authorized credentials file.   $credentialspath = expandhomedirectory(credentials_path);   if (file_exists($credentialspath)) {     $accesstoken = file_get_contents($credentialspath);   } else {     // request authorization user.     $authurl = $client->createauthurl();     printf("open following link in browser:\n%s\n", $authurl);     print 'enter verification code: ';     $authcode = trim(fgets(stdin));      // exchange authorization code access token.     $accesstoken = $client->authenticate($authcode);      // store credentials disk.     if(!file_exists(dirname($credentialspath))) {       mkdir(dirname($credentialspath), 0700, true);     }     file_put_contents($credentialspath, $accesstoken);     printf("credentials saved %s\n", $credentialspath);   }   $client->setaccesstoken($accesstoken);    // refresh token if it's expired.   if ($client->isaccesstokenexpired()) {     $client->refreshtoken($client->getrefreshtoken());     file_put_contents($credentialspath, $client->getaccesstoken());   }   return $client; }  /**  * expands home directory alias '~' full path.  * @param string $path path expand.  * @return string expanded path.  */ function expandhomedirectory($path) {   $homedirectory = getenv('home');   if (empty($homedirectory)) {     $homedirectory = getenv("homedrive") . getenv("homepath");   }   return str_replace('~', realpath($homedirectory), $path); }  // api client , construct service object. $client = getclient(); $service = new google_service_gmail($client);  // print labels in user's account. $user = 'me'; $results = $service->users_labels->listuserslabels($user);  if (count($results->getlabels()) == 0) {   print "no labels found.\n"; } else {   print "labels:\n";   foreach ($results->getlabels() $label) {     printf("- %s\n", $label->getname());   } } 


Comments

Popular posts from this blog

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Magento/PHP - Get phones on all members in a customer group -

session - Logging Out Using PHP -