本文整理汇总了PHP中Google_Client::setAssertionCredentials方法的典型用法代码示例。如果您正苦于以下问题:PHP Google_Client::setAssertionCredentials方法的具体用法?PHP Google_Client::setAssertionCredentials怎么用?PHP Google_Client::setAssertionCredentials使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Google_Client
的用法示例。
在下文中一共展示了Google_Client::setAssertionCredentials方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: make
/**
* @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']));
}
示例2: __construct
/**
* @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);
}
示例3: getClient
/**
* @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;
}
示例4: 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;
}
}
示例5: createAnalyticsService
/**
* @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;
}
示例6: 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;
}
示例7: 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;
}
示例8: 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;
}
示例9: do_something_with_user
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");
}
}
示例10: 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;
}
}
示例11: __construct
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);
}
示例12: 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);
}
示例13: __construct
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;
}
示例14: createClientFromJson
/**
* 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;
}
示例15: auth
private function auth()
{
$client = new Google_Client();
$client->setAssertionCredentials($this->credentials);
if ($client->getAuth()->isAccessTokenExpired()) {
$client->getAuth()->refreshTokenWithAssertion();
}
return $client;
}