本文整理汇总了PHP中Google_Client::setAuthConfig方法的典型用法代码示例。如果您正苦于以下问题:PHP Google_Client::setAuthConfig方法的具体用法?PHP Google_Client::setAuthConfig怎么用?PHP Google_Client::setAuthConfig使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Google_Client
的用法示例。
在下文中一共展示了Google_Client::setAuthConfig方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: instantiateClient
private function instantiateClient()
{
$this->client = new \Google_Client();
$this->client->setApplicationName($this->config['applicationName']);
$this->client->setAuthConfig($this->config['jsonFilePath']);
$this->client->setScopes($this->config['scopes']);
}
示例2: indexAction
/**
* @Route("/gatest2", name="front_ga2")
*
* @param Request $request
* @return \Symfony\Component\HttpFoundation\Response
*/
public function indexAction(Request $request)
{
$this->client = $this->get('GoogleClient');
$this->client->setAuthConfig($this->getParameter('googleCredentialsFile'));
$this->client->setApplicationName('Pingvin');
$this->client->setScopes($this->getParameter('googleAnalyticsAuthUrl'));
$this->analyticsService = $this->get('GoogleAnalyticsService');
$accounts = $this->analyticsService->management_accounts->listManagementAccounts();
$data = array();
if (count($accounts->getItems()) > 0) {
$items = $accounts->getItems();
foreach ($items as $item) {
$id = $item->getId();
$properties = $this->analyticsService->management_webproperties->listManagementWebproperties($id);
$items_e = $properties->getItems();
foreach ($items_e as $item_e) {
$profiles = $this->analyticsService->management_profiles->listManagementProfiles($id, $item_e->getId());
$items_ee = $profiles->getItems();
foreach ($items_ee as $item_ee) {
$data[] = array($item_ee->getId(), $item_e->getId());
}
}
}
var_dump('<pre>', $data);
}
return $this->render('CronBundle::message.html.twig', array('message' => '...'));
}
示例3: initializeObject
/**
* Initialize the google calendar
*
* @throws \KevinDitscheid\KdCalendar\Exception\NoAuthDataException
*/
public function initializeObject()
{
$this->settings = \KevinDitscheid\KdCalendar\Utility\ExtensionUtility::getMergedExtensionConfiguration();
$this->client = new \Google_Client();
$this->client->setApplicationName($this->settings['applicationName']);
$this->client->setScopes(\Google_Service_Calendar::CALENDAR_READONLY);
if ($this->settings['auth']['jsonFile']) {
$this->client->setAuthConfigFile($this->settings['auth']['jsonFile']);
} elseif ($this->settings['auth']['jsonString']) {
$this->client->setAuthConfig($this->settings['auth']['jsonString']);
} else {
throw new \KevinDitscheid\KdCalendar\Exception\NoAuthDataException("No auth data is provided for Google Calendar!", 1454958940);
}
$this->client->setAccessType(self::ACCESS_TYPE_OFFLINE);
}
示例4: validateEntity
/**
* @param Entity\CloudCredentials $entity
* @param Entity\CloudCredentials $prevConfig
*
* @throws ApiErrorException
*/
public function validateEntity($entity, $prevConfig = null)
{
parent::validateEntity($entity, $prevConfig);
$ccProps = $entity->properties;
$prevCcProps = isset($prevConfig) ? $prevConfig->properties : null;
if ($this->needValidation($ccProps, $prevCcProps)) {
$ccProps[Entity\CloudCredentialsProperty::GCE_ACCESS_TOKEN] = "";
try {
$client = new \Google_Client();
$client->setApplicationName("Scalr GCE");
$client->setScopes(['https://www.googleapis.com/auth/compute']);
$key = base64_decode($ccProps[Entity\CloudCredentialsProperty::GCE_KEY]);
// If it's not a json key we need to convert PKCS12 to PEM
if (!$ccProps[Entity\CloudCredentialsProperty::GCE_JSON_KEY]) {
@openssl_pkcs12_read($key, $certs, 'notasecret');
$key = $certs['pkey'];
}
$client->setAuthConfig(['type' => 'service_account', 'project_id' => $ccProps[Entity\CloudCredentialsProperty::GCE_PROJECT_ID], 'private_key' => $key, 'client_email' => $ccProps[Entity\CloudCredentialsProperty::GCE_SERVICE_ACCOUNT_NAME], 'client_id' => $ccProps[Entity\CloudCredentialsProperty::GCE_CLIENT_ID]]);
$client->setClientId($ccProps[Entity\CloudCredentialsProperty::GCE_CLIENT_ID]);
$gce = new \Google_Service_Compute($client);
$gce->zones->listZones($ccProps[Entity\CloudCredentialsProperty::GCE_PROJECT_ID]);
} catch (Exception $e) {
throw new ApiErrorException(400, ErrorMessage::ERR_INVALID_VALUE, "Provided GCE credentials are incorrect: ({$e->getMessage()})");
}
$entity->status = Entity\CloudCredentials::STATUS_ENABLED;
}
}
示例5: add_google_client
public function add_google_client()
{
$auth_config = $this->get_auth_config();
if (!empty($auth_config)) {
try {
$client = new Google_Client();
$client->setAuthConfig($this->get_auth_config());
$client->addScope(Google_Service_Analytics::ANALYTICS_READONLY);
$client->setAccessType('offline');
$token = $this->get_token();
if ($token) {
$client->setAccessToken($token);
}
if ($client->isAccessTokenExpired()) {
$refresh_token = $this->get_refresh_token();
if ($refresh_token) {
$client->refreshToken($refresh_token);
$this->update_token($client->getAccessToken());
}
}
$this->client = $client;
$this->service = new Google_Service_Analytics($this->client);
} catch (Exception $e) {
$message = 'Google Analytics Error[' . $e->getCode() . ']: ' . $e->getMessage();
$this->disconnect($message);
error_log($message, E_USER_ERROR);
return;
}
}
}
示例6: run
public function run()
{
require_once 'vendor/autoload.php';
$client = new Google_Client();
$client->setAuthConfig(array("type" => "service_account", "client_id" => $this->config['client_id'], "client_email" => $this->config['client_email'], "private_key" => $this->config['#private_key'], "signing_algorithm" => "HS256"));
$client->setApplicationName("GSC_Reports_Download");
$client->setScopes(['https://www.googleapis.com/auth/webmasters.readonly']);
$service = new Google_Service_Webmasters($client);
$this->getCrawlErrorsCounts($service, $this->config['site_url']);
}
示例7: getService
/**
* @return \Google_Service_Analytics
* @throws \Exception
* @throws \Google_Exception
*/
public function getService($token = null)
{
$application = $this->applicationService->getApplication(self::RESOURCE_OWNER);
if ($token === null) {
$token = $this->getToken();
}
$authConfig = array('web' => array('client_id' => $application->getKey(), 'client_secret' => $application->getSecret()));
$client = new \Google_Client();
$client->setAuthConfig(json_encode($authConfig));
$client->setAccessToken(json_encode(array('access_token' => $token->getAccessToken(), 'refresh_token' => $token->getRefreshToken())));
return new \Google_Service_Analytics($client);
}
示例8: getGoogleClient
/**
* @return Google_Client
*/
private function getGoogleClient()
{
if (is_null($this->client)) {
if (!class_exists('Google_Client')) {
throw new Exceptions\ProviderFailureException('Could not find the Google_Client class', 404);
}
$this->client = new \Google_Client();
$this->client->setApplicationName('Most_Popular');
$this->client->setAuthConfig($this->authConfigFile);
}
return $this->client;
}
示例9: useAssertCredentials
/**
* Determine and use credentials if user has set them.
* @param $userEmail
* @return bool used or not
*/
protected function useAssertCredentials($userEmail = '')
{
$serviceJsonUrl = array_get($this->config, 'service.file', '');
if (empty($serviceJsonUrl)) {
return false;
}
$this->client->setAuthConfig($serviceJsonUrl);
if ($userEmail) {
$this->client->setSubject($userEmail);
}
return true;
}
示例10: getClient
protected function getClient()
{
if (null === $this->client) {
$this->client = new \Google_Client();
$this->client->setAuthConfig($this->credentials);
$this->client->setApplicationName($this->name);
foreach ($this->services as $serviceName => $service) {
if (!isset($service['class'])) {
throw new InvalidConfigException("Not set service class for service \"{$serviceName}\"");
}
$service['scopes'] = (array) $service['scopes'];
if (empty($service['scopes'])) {
throw new InvalidConfigException("Not set scopes for service \"{$serviceName}\"");
}
$this->client->addScope($service["scopes"]);
}
$scopes = $this->client->getScopes();
if (empty($scopes)) {
throw new InvalidConfigException("Not set scopes for application \"{$this->name}\"");
}
}
return $this->client;
}
示例11: testJsonConfig
public function testJsonConfig()
{
// Device config
$config = new Google_Config();
$client = new Google_Client($config);
$device = '{"installed":{"auth_uri":"https://accounts.google.com/o/oauth2/auth","client_secret"' . ':"N0aHCBT1qX1VAcF5J1pJAn6S","token_uri":"https://accounts.google.com/o/oauth2/token",' . '"client_email":"","redirect_uris":["urn:ietf:wg:oauth:2.0:oob","oob"],"client_x509_cert_url"' . ':"","client_id":"123456789.apps.googleusercontent.com","auth_provider_x509_cert_url":' . '"https://www.googleapis.com/oauth2/v1/certs"}}';
$dObj = json_decode($device);
$client->setAuthConfig($device);
$cfg = $config->getClassConfig('Google_Auth_OAuth2');
$this->assertEquals($cfg['client_id'], $dObj->installed->client_id);
$this->assertEquals($cfg['client_secret'], $dObj->installed->client_secret);
$this->assertEquals($cfg['redirect_uri'], $dObj->installed->redirect_uris[0]);
// Web config
$config = new Google_Config();
$client = new Google_Client($config);
$web = '{"web":{"auth_uri":"https://accounts.google.com/o/oauth2/auth","client_secret"' . ':"lpoubuib8bj-Fmke_YhhyHGgXc","token_uri":"https://accounts.google.com/o/oauth2/token"' . ',"client_email":"123456789@developer.gserviceaccount.com","client_x509_cert_url":' . '"https://www.googleapis.com/robot/v1/metadata/x509/123456789@developer.gserviceaccount.com"' . ',"client_id":"123456789.apps.googleusercontent.com","auth_provider_x509_cert_url":' . '"https://www.googleapis.com/oauth2/v1/certs"}}';
$wObj = json_decode($web);
$client->setAuthConfig($web);
$cfg = $config->getClassConfig('Google_Auth_OAuth2');
$this->assertEquals($cfg['client_id'], $wObj->web->client_id);
$this->assertEquals($cfg['client_secret'], $wObj->web->client_secret);
$this->assertEquals($cfg['redirect_uri'], '');
}
示例12:
<?php
// MUST be using composer
require_once '/var/www/relle/vendor/autoload.php';
session_start();
$client = new Google_Client();
// Name of proj in GoogleDeveloperConsole
$client->setApplicationName("relle-analytics");
// Generated in GoogleDeveloperConsole --> Credentials --> Service Accounts
$client->setAuthConfig('/var/www/relle/relle-analytics-3753dd041a88.json');
$client->addScope(Google_Service_Analytics::ANALYTICS_READONLY);
// Grab token if it's set
if (isset($_SESSION['service_token'])) {
$client->setAccessToken($_SESSION['service_token']);
}
// Refresh if expired
if ($client->isAccessTokenExpired()) {
$client->refreshTokenWithAssertion();
}
// Pin to Session
$_SESSION['service_token'] = $client->getAccessToken();
$myToken = $client->getAccessToken();
?>
{{Analytics::trackEvent('Página', 'Logs')}}
@extends ('layout.dashboard')
@section('page')
{{trans('interface.name', ['page'=>trans('log.title')])}}
@stop
@section("title_inside")
示例13: pageHeader
echo pageHeader("Retrieving An Id Token");
/*************************************************
* Ensure you've downloaded your oauth credentials
************************************************/
if (!($oauth_credentials = getOAuthCredentialsFile())) {
echo missingOAuth2CredentialsWarning();
return;
}
/************************************************
* NOTICE:
* The redirect URI is to the current page, e.g:
* http://localhost:8080/idtoken.php
************************************************/
$redirect_uri = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
$client = new Google_Client();
$client->setAuthConfig($oauth_credentials);
$client->setRedirectUri($redirect_uri);
$client->setScopes('email');
/************************************************
* If we're logging out we just need to clear our
* local access token in this case
************************************************/
if (isset($_REQUEST['logout'])) {
unset($_SESSION['id_token_token']);
}
/************************************************
* If we have a code back from the OAuth 2.0 flow,
* we need to exchange that with the
* Google_Client::fetchAccessTokenWithAuthCode()
* function. We store the resultant access token
* bundle in the session, and redirect to ourself.
示例14: testApplicationDefaultCredentialsWithSubject
public function testApplicationDefaultCredentialsWithSubject()
{
$this->checkServiceAccountCredentials();
$credentialsFile = getenv('GOOGLE_APPLICATION_CREDENTIALS');
$sub = 'sub123';
$client = new Google_Client();
$client->setAuthConfig($credentialsFile);
$client->setSubject($sub);
$http = new Client();
$client->authorize($http);
$this->checkAuthHandler($http, 'AuthToken');
$this->checkCredentials($http, 'Google\\Auth\\Credentials\\ServiceAccountCredentials', $sub);
}
示例15: implode
// Change to the project root, to simplify resolving paths
chdir(dirname(__DIR__));
require 'vendor/autoload.php';
//require_once __DIR__ . '/vendor/autoload.php';
use zaboy\utils\Api\Gmail as ApiGmail;
define('APPLICATION_NAME', 'Gmail API PHP Quickstart');
define('CREDENTIALS_PATH', ApiGmail::CREDENTIALS_PATH);
define('CLIENT_SECRET_PATH', 'www/cfg/client_secret.json');
// If modifying these scopes, delete your previously saved credentials
// at ~/.credentials/gmail-php-quickstart.json
define('SCOPES', implode(' ', array(Google_Service_Gmail::GMAIL_READONLY)));
$client = new Google_Client();
$client->setApplicationName(APPLICATION_NAME);
$client->setScopes(SCOPES);
$client->setAuthConfig(CLIENT_SECRET_PATH);
$client->setAccessType('offline');
// Load previously authorized credentials from a file.
$credentialsPath = ApiGmail::expandHomeDirectory(CREDENTIALS_PATH);
if (file_exists($credentialsPath)) {
printf("Credentials exist in %s\n", $credentialsPath);
echo PHP_EOL . 'Delete it for remake and restsrt this script';
} else {
// Request authorization from the user.
$authUrl = $client->createAuthUrl();
printf("Open the following link in your browser:\n%s\n", $authUrl);
print 'Enter verification code: ';
$authCode = trim(fgets(STDIN));
// Exchange authorization code for an access token.
$accessToken = $client->fetchAccessTokenWithAuthCode($authCode);
// Store the credentials to disk.