/** * @return \Google_Client */ public function getClient() { if ($this->_client == null) { $this->_client = new Google_Client(); $this->_client->setApplicationName($this->appName); $key = file_get_contents(Yii::getAlias($this->keyFile)); $cred = new Google_Auth_AssertionCredentials($this->serviceAccountEmail, $this->scopes, $key); $this->_client->setAssertionCredentials($cred); if ($this->_client->getAuth()->isAccessTokenExpired()) { $this->_client->getAuth()->refreshTokenWithAssertion($cred); } } return $this->_client; }
private function getService() { // Creates and returns the Analytics service object. // Load the Google API PHP Client Library. ///Users/mustafahanif/WebstormProjects/influence/application/vendor/google-api-php-client/src/Google/autoload.php $path = dirname(__DIR__) . '/vendor/google-api-php-client/src/Google/autoload.php'; require_once $path; // Use the developers console and replace the values with your // service account email, and relative location of your key file. $service_account_email = '*****@*****.**'; $key_file_location = dirname(__DIR__) . '/vendor/client_key.p12'; // Create and configure a new client object. $client = new Google_Client(); $client->setApplicationName("HelloAnalytics"); $analytics = new Google_Service_Analytics($client); // Read the generated client_secrets.p12 key. $key = file_get_contents($key_file_location); //echo $key; $cred = new Google_Auth_AssertionCredentials($service_account_email, array(Google_Service_Analytics::ANALYTICS_READONLY), $key); //echo $cred; $client->setAssertionCredentials($cred); if ($client->getAuth()->isAccessTokenExpired()) { $client->getAuth()->refreshTokenWithAssertion($cred); } return $analytics; }
/** * @param string $name * @return \League\Flysystem\AdapterInterface * @throws \RuntimeException */ public static function make($name) { $connections = Config::get('storage.connections'); if (!isset($connections[$name])) { throw new \RuntimeException(sprintf('The storage connection %d does not exist.', $name)); } $connection = $connections[$name]; $connection['adapter'] = strtoupper($connection['adapter']); switch ($connection['adapter']) { case 'LOCAL': return new Local($connection['root_path'], $connection['public_url_base']); case 'RACKSPACE': $service = isset($connection['service']) ? Config::get($connection['service']) : Config::get('services.rackspace'); $client = new Rackspace($service['api_endpoint'], array('username' => $service['username'], 'tenantName' => $service['tenant_name'], 'apiKey' => $service['api_key'])); $store = $client->objectStoreService($connection['store'], $connection['region']); $container = $store->getContainer($connection['container']); return new RackspaceAdapter($container); case 'AWS': $service = isset($connection['service']) ? Config::get($connection['service']) : Config::get('services.aws'); $client = S3Client::factory(array('credentials' => array('key' => $service['access_key'], 'secret' => $service['secret_key']), 'region' => $service['region'], 'version' => 'latest')); return new AwsS3Adapter($client, $connection['bucket']); case 'GCLOUD': $service = isset($connection['service']) ? Config::get($connection['service']) : Config::get('services.google_cloud'); $credentials = new \Google_Auth_AssertionCredentials($service['service_account'], [\Google_Service_Storage::DEVSTORAGE_FULL_CONTROL], file_get_contents($service['key_file']), $service['secret']); $config = new \Google_Config(); $config->setAuthClass(GoogleAuthOAuth2::class); $client = new \Google_Client($config); $client->setAssertionCredentials($credentials); $client->setDeveloperKey($service['developer_key']); $service = new \Google_Service_Storage($client); return new GoogleStorageAdapter($service, $connection['bucket']); } throw new \RuntimeException(sprintf('The storage adapter %s is invalid.', $connection['adapter'])); }
function getService() { // Creates and returns the Analytics service object. // Load the Google API PHP Client Library. require_once 'vendor/autoload.php'; // Use the developers console and replace the values with your // service account email, and relative location of your key file. //Charlie's email // $service_account_email = '*****@*****.**'; //My email $service_account_email = '*****@*****.**'; $key_file_location = 'client_secrets.p12'; // Create and configure a new client object. $client = new Google_Client(); $client->setApplicationName("HelloAnalytics"); $analytics = new Google_Service_Analytics($client); // Read the generated client_secrets.p12 key. $key = file_get_contents($key_file_location); $cred = new Google_Auth_AssertionCredentials($service_account_email, array(Google_Service_Analytics::ANALYTICS_READONLY), $key); $client->setAssertionCredentials($cred); if ($client->getAuth()->isAccessTokenExpired()) { $client->getAuth()->refreshTokenWithAssertion($cred); } return $analytics; }
function gapps_service($domain) { global $directory; $info = libraries_load('google-api-php-client'); if (!$info['loaded']) { drupal_set_message(t('Can`t authenticate with google as library is missing check Status report or Readme for requirements, download from') . l('https://github.com/google/google-api-php-client/archive/master.zip', 'https://github.com/google/google-api-php-client/archive/master.zip'), 'error'); return FALSE; } $client_email = variable_get('gapps_service_client_email'); $file = file_load(variable_get('gapps_service_private_key')); $private_key = file_get_contents(drupal_realpath($file->uri)); if ($domain == 'teacher') { $user_to_impersonate = variable_get('gapps_teacher_admin'); } else { $user_to_impersonate = variable_get('gapps_student_admin'); } $scopes = array('https://www.googleapis.com/auth/admin.directory.orgunit', 'https://www.googleapis.com/auth/admin.directory.group', 'https://www.googleapis.com/auth/admin.directory.group.member', 'https://www.googleapis.com/auth/admin.directory.user', 'https://www.googleapis.com/auth/admin.directory.user.alias'); $credentials = new Google_Auth_AssertionCredentials($client_email, $scopes, $private_key); $credentials->sub = $user_to_impersonate; $client = new Google_Client(); $client->setApplicationName('Drupal gapps module'); $client->setAssertionCredentials($credentials); while ($client->getAuth()->isAccessTokenExpired()) { $client->getAuth()->refreshTokenWithAssertion($credentials); } $directory = new Google_Service_Directory($client); $_SESSION['gapps_' . $domain . '_access_token'] = $client->getAccessToken(); if ($_SESSION['gapps_' . $domain . '_access_token']) { return $directory; } else { return NULL; } }
function gevent_service() { global $calendar; $info = libraries_load('google-api-php-client'); if (!$info['loaded']) { drupal_set_message(t('Can`t authenticate with google as library is missing check Status report or Readme for requirements, download from') . l('https://github.com/google/google-api-php-client/archive/master.zip', 'https://github.com/google/google-api-php-client/archive/master.zip'), 'error'); return FALSE; } $client_email = variable_get('gapps_service_client_email'); $file = file_load(variable_get('gapps_service_private_key')); $private_key = file_get_contents(drupal_realpath($file->uri)); $user_to_impersonate = variable_get('gevent_admin'); $scopes = array('https://www.googleapis.com/auth/calendar'); $credentials = new Google_Auth_AssertionCredentials($client_email, $scopes, $private_key, 'notasecret', 'http://oauth.net/grant_type/jwt/1.0/bearer', $user_to_impersonate); $client = new Google_Client(); $client->setApplicationName('Drupal gevent module'); $client->setAssertionCredentials($credentials); while ($client->getAuth()->isAccessTokenExpired()) { $client->getAuth()->refreshTokenWithAssertion(); } $calendar = new Google_Service_Calendar($client); $_SESSION['gevent_access_token'] = $client->getAccessToken(); if ($_SESSION['gevent_access_token']) { return $calendar; } else { return NULL; } }
function getTheList() { require 'src/Google/autoload.php'; $service_account_name = "*****@*****.**"; $key_file_location = "yd-tn.p12"; $client = new Google_Client(); $client->setApplicationName("Members"); $directory = new Google_Service_Directory($client); if (isset($_SESSION['service_token']) && $_SESSION['service_token']) { $client->setAccessToken($_SESSION['service_token']); } $key = file_get_contents($key_file_location); $cred = new Google_Auth_AssertionCredentials($service_account_name, array('https://www.googleapis.com/auth/admin.directory.user'), $key); $cred->sub = "*****@*****.**"; $client->setAssertionCredentials($cred); if ($client->getAuth()->isAccessTokenExpired()) { $client->getAuth()->refreshTokenWithAssertion($cred); } $_SESSION['service_token'] = $client->getAccessToken(); $param = array(); $param['domain'] = "youthdecides.org"; $list = $directory->users->listUsers($param); $tab = array(); $i = 0; foreach ($list as $user) { $tab[$i]['nom'] = strtolower($user->getName()->getFullName()); $tab[$i]['mail'] = $user->getPrimaryEmail(); $i++; } //echo json_encode($tab); return $tab; }
private function auth() { $client = new Google_Client(); $client->setAssertionCredentials($this->credentials); if ($client->getAuth()->isAccessTokenExpired()) { $client->getAuth()->refreshTokenWithAssertion(); } return $client; }
/** * Return the authenticated Google Client * * @return \Google_Client */ private function getClient() { $credentials = new \Google_Auth_AssertionCredentials($this->parameters['client_email'], array($this->parameters['api_url']), file_get_contents($this->container->get('kernel')->getRootDir() . "/../" . $this->parameters['api_key_file'])); $client = new \Google_Client(); $client->setAssertionCredentials($credentials); if ($client->getAuth()->isAccessTokenExpired()) { $client->getAuth()->refreshTokenWithAssertion(); } return $client; }
/** * Returns an authorized API client. * * @param string $email * @return \Google_Client the authorized client object */ function getClient($email) { $privateKey = file_get_contents('google-documents-exporter.p12'); $credentials = new Google_Auth_AssertionCredentials($email, SCOPES, $privateKey); $client = new Google_Client(); $client->setAssertionCredentials($credentials); if ($client->getAuth()->isAccessTokenExpired()) { $client->getAuth()->refreshTokenWithAssertion(); } return $client; }
/** * auth and get service instance */ public function getServiceCalendar() { $scopes = array('https://www.googleapis.com/auth/calendar'); $credential = new Google_Auth_AssertionCredentials($this->auth_email, $scopes, $this->p12_key); $client = new Google_Client(); $client->setAssertionCredentials($credential); if ($client->getAuth()->isAccessTokenExpired()) { $client->getAuth()->refreshTokenWithAssertion($credential); } return new Google_Service_Calendar($client); }
private function _GC_getService() { $client = new Google_Client(); $client->setApplicationName("Client_Gestion_Material_Eventos"); $creds = new Google_Auth_AssertionCredentials(Configure::read('GC_email'), array('https://www.googleapis.com/auth/calendar'), file_get_contents(APP . Configure::read('GC_keyfile'))); $client->setAssertionCredentials($creds); if ($client->getAuth()->isAccessTokenExpired()) { $client->getAuth()->refreshTokenWithAssertion($creds); } $service = new Google_Service_Calendar($client); return $service; }
public static function getGoogleTokenFromKeyFile() { $client = new \Google_Client(); $client->setClientId(SERVICE_CLIENT_ID); $cred = new \Google_Auth_AssertionCredentials(SERVICE_EMAIL, array('https://spreadsheets.google.com/feeds'), file_get_contents(__DIR__ . '/../service_api.p12')); $client->setAssertionCredentials($cred); if ($client->getAuth()->isAccessTokenExpired()) { $client->getAuth()->refreshTokenWithAssertion($cred); } $service_token = json_decode($client->getAccessToken()); return $service_token->access_token; }
function getGoogleTokenFromKeyFile($clientId, $clientEmail, $pathToP12File) { $client = new Google_Client(); $client->setClientId($clientId); $cred = new Google_AssertionCredentials($clientEmail, array('https://spreadsheets.google.com/feeds'), file_get_contents($pathToP12File)); $client->setAssertionCredentials($cred); if ($client->getAuth()->isAccessTokenExpired()) { $client->getAuth()->refreshTokenWithAssertion($cred); } $service_token = json_decode($client->getAccessToken()); return $service_token->access_token; }
/** * Returns an authorized API client. * @return Google_Client the authorized client object */ function getClient() { $client_email = '*****@*****.**'; $private_key = file_get_contents('/var/www/asirb/vendor/google/intranet.p12'); $scopes = array('https://www.googleapis.com/auth/admin.directory.user'); $credentials = new Google_Auth_AssertionCredentials($client_email, $scopes, $private_key, 'notasecret', 'http://oauth.net/grant_type/jwt/1.0/bearer', '*****@*****.**'); $client = new Google_Client(); $client->setAssertionCredentials($credentials); if ($client->getAuth()->isAccessTokenExpired()) { $client->getAuth()->refreshTokenWithAssertion(); } return $client; }
/** * Connect to Google API via oAuth 2.0 * * @return Object Returns oAuth response */ public function LogIn() { /* OAUTH 2.0 */ $private_key = self::getPrivateKey(); $scopes = array('https://www.googleapis.com/auth/webmasters.readonly'); $credentials = new Google_Auth_AssertionCredentials(Config::OAUTH_CREDENTIALS_EMAIL, $scopes, $private_key); $client = new Google_Client(); $client->setAssertionCredentials($credentials); if ($client->getAuth()->isAccessTokenExpired()) { $client->getAuth()->refreshTokenWithAssertion(); } return $client; }
/** * @param ContainerInterface $container * @param TranslatorInterface $translator * @param LoggerInterface $logger * * @throws InvalidConfigurationException */ public function __construct(ContainerInterface $container, TranslatorInterface $translator, LoggerInterface $logger) { $this->container = $container; // Check if we have the API key $rootDir = $this->container->getParameter('kernel.root_dir'); $configDir = $rootDir . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR; $apiKeyFile = $configDir . $this->container->getParameter('dms.service_account_key_file'); if (!file_exists($apiKeyFile)) { throw new InvalidConfigurationException('Store your Google API key in ' . $apiKeyFile . ' - see https://code.google.com/apis/console'); } // Perform API authentication $apiKeyFileContents = file_get_contents($apiKeyFile); $serviceAccountEmail = $this->container->getParameter('dms.service_account_email'); $auth = new \Google_Auth_AssertionCredentials($serviceAccountEmail, array('https://www.googleapis.com/auth/drive'), $apiKeyFileContents); $this->client = new \Google_Client(); if (isset($_SESSION['service_token'])) { $this->client->setAccessToken($_SESSION['service_token']); } $this->client->setAssertionCredentials($auth); /* if ($this->client->getAuth()->isAccessTokenExpired()) { $this->client->getAuth()->refreshTokenWithAssertion($auth); } */ $this->translator = $translator; $this->logger = $logger; $this->service = new \Google_Service_Drive($this->client); }
/** * @return object | $service | Google Analytics Service Object used to run queries **/ private function createAnalyticsService() { /** * Create and Authenticate Google Analytics Service Object **/ $client = new Google_Client(); $client->setApplicationName(GOOGLE_API_APP_NAME); /** * Makes sure Private Key File exists and is readable. If you get an error, check path in apiConfig.php **/ if (!file_exists(GOOGLE_API_PRIVATE_KEY_FILE)) { array_push($GLOBALS['criticalErrors'], "CRITICAL-ERROR: Unable to find GOOGLE_API_PRIVATE_KEY_FILE p12 file at " . GOOGLE_API_PRIVATE_KEY_FILE); criticalErrorOccurred($criticalErrors, $errors); exit("CRITICAL-ERROR: Unable to find GOOGLE_API_PRIVATE_KEY_FILE p12 file at " . GOOGLE_API_PRIVATE_KEY_FILE . ' Backup aborted.'); } elseif (!is_readable(GOOGLE_API_PRIVATE_KEY_FILE)) { array_push($GLOBALS['criticalErrors'], "CRITICAL-ERROR: Unable to read GOOGLE_API_PRIVATE_KEY_FILE p12 file at " . GOOGLE_API_PRIVATE_KEY_FILE); criticalErrorOccurred($criticalErrors, $errors); exit("CRITICAL-ERROR: Unable to read GOOGLE_API_PRIVATE_KEY_FILE p12 file at " . GOOGLE_API_PRIVATE_KEY_FILE . ' Backup aborted.'); } $client->setAssertionCredentials(new Google_AssertionCredentials(GOOGLE_API_SERVICE_EMAIL, array('https://www.googleapis.com/auth/analytics.readonly'), file_get_contents(GOOGLE_API_PRIVATE_KEY_FILE))); $client->setClientId(GOOGLE_API_SERVICE_CLIENT_ID); $client->setUseObjects(true); $service = new Google_AnalyticsService($client); return $service; }
public function __construct($clientId, $serviceAccountName, $key) { $client = new Google_Client(); $client->setClientId($clientId); $client->setAssertionCredentials(new Google_Auth_AssertionCredentials($serviceAccountName, $this->scope, file_get_contents($key))); $this->sef = new Google_Service_Drive($client); }
function do_something_with_user($email) { global $key; $user_client = new Google_Client(); $user_client->setApplicationName("Google+ Domains API Sample"); $user_credentials = new Google_AssertionCredentials(SERVICE_ACCOUNT_EMAIL, array("https://www.googleapis.com/auth/plus.me", "https://www.googleapis.com/auth/plus.stream.read"), $key); // Set the API Client to act on behalf of the specified user $user_credentials->sub = $email; $user_client->setAssertionCredentials($user_credentials); $user_client->setClientId(CLIENT_ID); $plusService = new Google_PlusService($user_client); // Try to retrieve Google+ Profile information about the current user try { $result = $plusService->people->get("me"); } catch (Exception $e) { printf(" / Not a Google+ User<br><br>\n"); return; } printf(" / <a href=\"%s\">Google+ Profile</a>\n", $result["url"]); // Retrieve a list of Google+ activities for the current user $activities = $plusService->activities->listActivities("me", "user", array("maxResults" => 100)); if (isset($activities["items"])) { printf(" / %s activities found<br><br>\n", count($activities["items"])); } else { printf(" / No activities found<br><br>\n"); } }
public function dashboard_display() { $this->ci->load->model("user_model"); if (empty($this->ci->user_model->user->profile_id)) { return; } @session_start(); require_once APPPATH . 'third_party/Google_api/src/Google/autoload.php'; $client_id = '121864429952-2fb1efk8v9rhq46iud08hvg2sdcer3uu.apps.googleusercontent.com'; //Client ID $service_account_name = '*****@*****.**'; //Email Address $key_file_location = APPPATH . 'third_party/Google_api/src/Google/Pando-8c981025c45b.p12'; //key.p12 $client = new Google_Client(); $client->setApplicationName("ApplicationName"); $service = new Google_Service_Analytics($client); if (isset($_SESSION['service_token'])) { $client->setAccessToken($_SESSION['service_token']); } $key = file_get_contents($key_file_location); $cred = new Google_Auth_AssertionCredentials($service_account_name, array('https://www.googleapis.com/auth/analytics'), $key, 'notasecret'); $client->setAssertionCredentials($cred); if ($client->getAuth()->isAccessTokenExpired()) { $client->getAuth()->refreshTokenWithAssertion($cred); } $_SESSION['service_token'] = $client->getAccessToken(); $analytics = new Google_Service_Analytics($client); $profileId = "ga:95600714"; $profileId = "ga:" . $this->ci->user_model->user->profile_id; // die($profileId); $startDate = date('Y-m-d', strtotime('-31 days')); // 31 days from now $endDate = date('Y-m-d'); // todays date $metrics = "ga:sessions,ga:newUsers,ga:users,ga:percentNewSessions,ga:timeOnPage,ga:exitRate,ga:hits"; // $metrics = "ga:dataSource"; $optParams = array("dimensions" => "ga:date"); try { $results = $analytics->data_ga->get($profileId, $startDate, $endDate, $metrics, $optParams); } catch (Exception $e) { return; } $data_analytics = new stdClass(); $data_analytics->total_access = $results->totalsForAllResults["ga:sessions"]; $data_analytics->new_users_percentage = $results->totalsForAllResults["ga:percentNewSessions"]; $data_analytics->time_on_page = gmdate("H:i:s", $results->totalsForAllResults["ga:timeOnPage"]); $data_analytics->exit_rate = $results->totalsForAllResults["ga:exitRate"]; $data_analytics->hits = $results->totalsForAllResults["ga:hits"]; $data_analytics->rows = $results->rows; foreach ($data_analytics->rows as &$row) { $row["day"] = date("d", strtotime($row[0])); $row["month"] = date("m", strtotime($row[0])); $row["year"] = date("Y", strtotime($row[0])); } // dump($data_analytics); $data['report'] = $data_analytics; return $this->ci->load->view('libraries_view/new_analytics', $data, true); }
/** * Create a configured Google Client ready for Datastore use, using the JSON service file from Google Dev Console * * @param $str_json_file * @return \Google_Client */ public static function createClientFromJson($str_json_file) { $obj_client = new \Google_Client(); $obj_client->setAssertionCredentials($obj_client->loadServiceAccountJson($str_json_file, [\Google_Service_Datastore::DATASTORE, \Google_Service_Datastore::USERINFO_EMAIL])); // App Engine php55 runtime dev server problems... $obj_client->setClassConfig('Google_Http_Request', 'disable_gzip', TRUE); return $obj_client; }
public function __construct($email, $id, $key, $calendar = false) { $client = new Google_Client(); $client->setAssertionCredentials(new Google_AssertionCredentials($email, array('https://www.googleapis.com/auth/calendar'), $key)); $client->setClientId($id); $this->cal = new Google_CalendarService($client); $this->cal_name = $calendar; }
/** * Returns an authorized API client. * @return Google_Client the authorized client object */ public static function getClient() { $client = new Google_Client(); $client->setApplicationName(static::$applicationName); $client->setAssertionCredentials(new Google_Auth_AssertionCredentials(static::$serviceAccount['email'], static::$driveScope, file_get_contents(__DIR__ . '/' . static::$serviceAccount['keyPath']))); $client->setAccessType('offline'); $client->setClassConfig('Google_Cache_File', array('directory' => '/tmp/cache')); return $client; }
/** * Determine and use credentials if user has set them. * * @return boolean used or not */ protected function useAssertCredentials() { $account = array_get($this->config, 'service.account', ''); if (!empty($account)) { $cert = new \Google_Auth_AssertionCredentials(array_get($this->config, 'service.account', ''), array_get($this->config, 'service.scopes', []), file_get_contents(array_get($this->config, 'service.key', ''))); $this->client->setAssertionCredentials($cert); return true; } return false; }
function GetClient() { global $SETTINGS; $client = new Google_Client(); $client->setApplicationName("RapidReseller-PHP"); // Google_Auth_AssertionCredentials implements its own cache. $key = file_get_contents($SETTINGS['OAUTH2_PRIVATE_KEY']); $client->setAssertionCredentials(new Google_Auth_AssertionCredentials($SETTINGS['OAUTH2_SERVICE_ACCOUNT_EMAIL'], $SETTINGS['OAUTH2_SCOPES'], $key, 'notasecret', 'http://oauth.net/grant_type/jwt/1.0/bearer', $SETTINGS['RESELLER_ADMIN'])); return $client; }
function todays_categories() { $client = new Google_Client(); $client->setClientId(CLIENT_ID); $client->setAssertionCredentials(new Google_AssertionCredentials(SERVICE_ACCOUNT_NAME, array('https://www.googleapis.com/auth/calendar'), file_get_contents(KEY_FILE))); $service = new Google_CalendarService($client); $optParams = array('timeMin' => date('c', strtotime('today +10 hour')), 'timeMax' => date('c', strtotime('noon'))); $events = $service->events->listEvents('*****@*****.**', $optParams); preg_match('/【(.*?)】【(.*?)】【(.*?)】が読めます/', $events['items'][0]["summary"], $matches); return array($matches[1], $matches[2], $matches[3]); }
/** * @return \Google_Client */ protected function getGoogleClient($redirectUrl) { if (!$this->_googleClient) { $this->_googleClient = new \Google_Client(); $this->_googleClient->setUseObjects(TRUE); $this->_googleClient->setApplicationName($this->applicationName); $this->_googleClient->setAssertionCredentials(new \Google_AssertionCredentials($this->clientMail, array('https://www.googleapis.com/auth/analytics.readonly'), file_get_contents($this->keyFile))); $this->_googleClient->setClientId($this->clientId); $this->_googleClient->setRedirectUri($redirectUrl); } return $this->_googleClient; }
public function init() { parent::init(); // api dependencies $client = new Google_Client(); $client->setClassConfig('Google_Cache_File', 'directory', realpath(dirname(__FILE__) . '/../../giga_cache')); $client->setApplicationName($this->app_name); $client->setScopes(Google_Service_Analytics::ANALYTICS); $client->setAssertionCredentials(new Google_Auth_AssertionCredentials($this->client_email, array(Google_Service_Analytics::ANALYTICS), file_get_contents($this->keyfile))); $client->setClientID($this->client_id); $this->client = $client; }
/** * Initializes provided context. * * @param ContextInterface $context */ public function initialize(ContextInterface $context) { $client = new \Google_Client(); $client->setApplicationName('BehatGoogleAnalyticsExtension'); $client->setScopes(array('https://www.googleapis.com/auth/analytics.readonly')); $client->setClientId($this->parameters['client_id']); $key = file_get_contents($this->parameters['key_file_location']); $cred = new \Google_Auth_AssertionCredentials($this->parameters['service_account_name'], array('https://www.googleapis.com/auth/analytics.readonly'), $key); $client->setAssertionCredentials($cred); $service = new \Google_Service_Analytics($client); $context->setAnalyticsApiService($service); $context->setGoogleAnalyticsParameters($this->parameters); }