本文整理汇总了PHP中Google_Client::getAuth方法的典型用法代码示例。如果您正苦于以下问题:PHP Google_Client::getAuth方法的具体用法?PHP Google_Client::getAuth怎么用?PHP Google_Client::getAuth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Google_Client
的用法示例。
在下文中一共展示了Google_Client::getAuth方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getService
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 = 'testaccount@operating-rush-124305.iam.gserviceaccount.com';
$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;
}
示例2: gevent_service
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;
}
}
示例3: getService
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 = 'taco-tester@nodal-strength-118806.iam.gserviceaccount.com';
//My email
$service_account_email = 'test-1-service-account@decisive-force-119018.iam.gserviceaccount.com';
$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;
}
示例4: gapps_service
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;
}
}
示例5: getTheList
function getTheList()
{
require 'src/Google/autoload.php';
$service_account_name = "987694720165-oeqomp6saoe1q258ohn4kfg1h2erp2ih@developer.gserviceaccount.com";
$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 = "alaa@youthdecides.org";
$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;
}
示例6: dashboard_display
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 = '121864429952-2fb1efk8v9rhq46iud08hvg2sdcer3uu@developer.gserviceaccount.com';
//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);
}
示例7: auth
private function auth()
{
$client = new Google_Client();
$client->setAssertionCredentials($this->credentials);
if ($client->getAuth()->isAccessTokenExpired()) {
$client->getAuth()->refreshTokenWithAssertion();
}
return $client;
}
示例8: getClient
/**
* 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;
}
示例9: getClient
/**
* 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;
}
示例10: getServiceCalendar
/**
* 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);
}
示例11: getGoogleTokenFromKeyFile
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;
}
示例12: _GC_getService
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;
}
示例13: getGoogleTokenFromKeyFile
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;
}
示例14: LogIn
/**
* 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;
}
示例15: getClient
/**
* Returns an authorized API client.
* @return Google_Client the authorized client object
*/
function getClient()
{
$client_email = '119659802263-0bs0tltlr0hbu4hsbj33eoonahaootpk@developer.gserviceaccount.com';
$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', 'intranet@smt.ufrj.br');
$client = new Google_Client();
$client->setAssertionCredentials($credentials);
if ($client->getAuth()->isAccessTokenExpired()) {
$client->getAuth()->refreshTokenWithAssertion();
}
return $client;
}