本文整理汇总了PHP中Google_Client::setClassConfig方法的典型用法代码示例。如果您正苦于以下问题:PHP Google_Client::setClassConfig方法的具体用法?PHP Google_Client::setClassConfig怎么用?PHP Google_Client::setClassConfig使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Google_Client
的用法示例。
在下文中一共展示了Google_Client::setClassConfig方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
public function __construct($oauthClientId, $oauthClientSecret, $oAuthConfig = array())
{
$this->client = new \Google_Client();
$this->client->setClassConfig('Google_Auth_OAuth2', $oAuthConfig);
$this->client->setClientId($oauthClientId);
$this->client->setClientSecret($oauthClientSecret);
}
示例2: getClient
public function getClient()
{
$client = new Google_Client();
$client->setDeveloperKey(self::KEY);
if (strlen($this->token)) {
$client->setAccessToken($this->token);
}
if (strlen($this->memcacheHost)) {
$client->setClassConfig('Google_Cache_Memcache', 'host', $this->memcacheHost);
$client->setClassConfig('Google_Cache_Memcache', 'port', $this->memcachePort);
}
return $client;
}
示例3: 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;
}
示例4: __construct
/**
* Constructor stores the passed Google Client object, sets a bunch of config options from the config file, and also
* creates and instance of the \Google_Service_YouTube class and stores this for later use.
*
* @param \Google_Client $client
*/
public function __construct(\Google_Client $client)
{
$this->client = $client;
$this->client->setApplicationName(\Config::get('laravel-youtube::application_name'));
$this->client->setClientId(\Config::get('laravel-youtube::client_id'));
$this->client->setClientSecret(\Config::get('laravel-youtube::client_secret'));
$this->client->setScopes(\Config::get('laravel-youtube::scopes'));
$this->client->setAccessType(\Config::get('laravel-youtube::access_type'));
$this->client->setApprovalPrompt(\Config::get('laravel-youtube::approval_prompt'));
$this->client->setRedirectUri(\URL::to(\Config::get('laravel-youtube::redirect_uri')));
$this->client->setClassConfig('Google_Http_Request', 'disable_gzip', true);
$this->youtube = new \Google_Service_YouTube($this->client);
$accessToken = $this->getLatestAccessTokenFromDB();
if ($accessToken) {
$this->client->setAccessToken($accessToken);
}
}
示例5: getClient
/**
* 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;
}
示例6: init
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;
}
示例7: create_client
private function create_client()
{
$full_creds_file = $this->api_creds_file;
if (!file_exists($full_creds_file)) {
throw new \Exception("Cannot find file " . $full_creds_file, 1);
}
$client = new \Google_Client();
echo "Credentials File: " . $full_creds_file . PHP_EOL;
$cred = $client->loadServiceAccountJson($full_creds_file, array(\Google_Service_Analytics::ANALYTICS_READONLY));
// Setup authentication to Google.
// This is needed because we are running via a phar file
$client->setClassConfig("Google_IO_Curl", ["options" => [CURLOPT_CAINFO => $this->pem_file]]);
// re-auth if needed
if ($client->getAuth()->isAccessTokenExpired()) {
$client->getAuth()->refreshTokenWithAssertion($cred);
}
return $client;
}
示例8: cob_calendar_service
/**
* Lazy loads the google calendar service
*
* @return Google_Service_Calendar
*/
function cob_calendar_service()
{
static $client = null;
static $service = null;
if (!$service) {
if (!$client) {
libraries_load('google-api-php-client');
$json = json_decode(file_get_contents(DRUPAL_ROOT . '/' . conf_path() . '/credentials.json'));
$credentials = new \Google_Auth_AssertionCredentials($json->client_email, ['https://www.googleapis.com/auth/calendar.readonly'], $json->private_key);
$credentials->sub = variable_get('cob_google_email');
$client = new \Google_Client();
$client->setClassConfig('Google_Cache_File', 'directory', DRUPAL_ROOT . '/' . conf_path() . '/files/Google_Client');
$client->setAssertionCredentials($credentials);
if ($client->getAuth()->isAccessTokenExpired()) {
$client->getAuth()->refreshTokenWithAssertion();
}
}
$service = new \Google_Service_Calendar($client);
}
return $service;
}
示例9: unset
<?php
use rtens\ucdi\Bootstrapper;
use rtens\ucdi\GoogleCalendar;
use rtens\ucdi\SettingsStore;
use watoki\collections\Collection;
use watoki\curir\protocol\Url;
require_once __DIR__ . '/vendor/autoload.php';
session_start();
$baseUrl = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
$client = new Google_Client();
$client->setApplicationName('U Can Do It');
$client->setScopes([Google_Service_Calendar::CALENDAR, Google_Service_Oauth2::USERINFO_EMAIL]);
$client->setAuthConfigFile(__DIR__ . '/user/client_secret.json');
$client->setClassConfig(Google_Http_Request::class, "disable_gzip", true);
if (isset($_GET['logout'])) {
unset($_SESSION['token']);
echo "Logged-out <a href='?'>Log-in</a>";
exit;
}
if (isset($_GET['code'])) {
$client->authenticate($_GET['code']);
$_SESSION['token'] = $client->getAccessToken();
header('Location: ' . ($_SESSION['targetUrl'] ?: '/'));
exit;
}
if (isset($_SESSION['token'])) {
$client->setAccessToken($_SESSION['token']);
}
$redirectToAuthUrl = function () use($client) {
$_SESSION['targetUrl'] = (string) Url::fromString($_SERVER['REQUEST_URI'])->withParameters(Collection::toCollections($_REQUEST));
示例10: get_google_client
/**
* @since 1.0
*
* @param bool $set_access_token If the access token should be set (default: true)
*
* @return Google_Client
*/
public function get_google_client($set_access_token = true)
{
if (isset($this->_client)) {
return $this->_client;
}
$client = new Google_Client();
$client->setClassConfig('Google_IO_Abstract', 'request_timeout_seconds', 10);
if ((bool) WPB_Google_Drive_Cdn_Settings::get_setting('temp_dir_change')) {
// temp dir from the settings
$temp_dir = WPB_Google_Drive_Cdn_Settings::get_setting('temp_dir');
// if empty temp dir build it up
if (empty($temp_dir)) {
$upload_dir = wp_upload_dir();
$temp_dir = str_replace($upload_dir['subdir'], '', $upload_dir['path']);
}
$client->setClassConfig('Google_Cache_File', 'directory', $temp_dir);
}
// Get your credentials from the APIs Console
$client->setClientId(WPB_Google_Drive_Cdn_Settings::get_setting('client_id'));
$client->setClientSecret(WPB_Google_Drive_Cdn_Settings::get_setting('client_secret'));
$client->setRedirectUri(admin_url('options-general.php?page=wpbgdc'));
$client->addScope(Google_Service_Drive::DRIVE);
$token = WPB_Google_Drive_Cdn_Settings::get_setting('token', 'wpbgdc_oauth_token');
// check if access token has expired
// for this set the token
if ($set_access_token) {
if ('' != $token) {
$client->setAccessToken($token);
}
}
// check if the token has expired. If so: request a new one
if ($client->isAccessTokenExpired()) {
$token = json_decode($token, true);
if ($token == null) {
$this->set_error('Could not json decode the refresh token to ask for a new token. Please try to re-authenticate with your Google Drive.', false);
}
if (!isset($token['refresh_token'])) {
$this->set_error('Invalid refresh token format. Please try to re-authenticate with your Google Drive.', false);
} else {
try {
$client->refreshToken($token['refresh_token']);
$refreshed_token = $client->getAccessToken();
if (!is_string($refreshed_token)) {
throw new Exception('Got an invalid token while refreshing. Please try to re-authenticate with your Google Drive.');
} else {
WPB_Google_Drive_Cdn_Settings::set_setting('token', $refreshed_token, 'wpbgdc_oauth_token');
}
} catch (Exception $e) {
$this->set_error($e->getMessage() . ' (wpbgdc: refresh_token)', false);
}
}
}
$this->_client = $client;
return $this->_client;
}
示例11: header
<?php
set_include_path(get_include_path() . PATH_SEPARATOR . '../../google-api-php-client/src/Google');
include 'config.php';
require_once 'log_data_service.php';
require_once 'pov_data_service.php';
require_once 'autoload.php';
//session_start();
$client = new Google_Client();
$client->setAuthConfigFile('client_secrets.json');
$client->setClassConfig("Google_Auth_OAuth2", 'access_type', 'offline');
$client->setRedirectUri('http://newsline.world/php/oauth2.php');
$client->addScope(Google_Service_Webmasters::WEBMASTERS);
if (!isset($_GET['code'])) {
$auth_url = $client->createAuthUrl();
header('Location: ' . filter_var($auth_url, FILTER_SANITIZE_URL));
} else {
$client->authenticate($_GET['code']);
$access_token = $client->getAccessToken();
// $client->revokeToken();
$refresh_token = $client->getRefreshToken();
//$refresh_token = $access_token['refresh_token'];
//handle access_token
$ds = new PovDataService($conf['dsn'], $conf['dbname'], $conf['dbpassword'], array(PDO::ATTR_PERSISTENT => false));
$ds->setGoogleToken("auth", $access_token, $refresh_token);
$redirect_uri = 'http://' . $_SERVER['HTTP_HOST'] . '/';
header('Location: ' . filter_var($redirect_uri, FILTER_SANITIZE_URL));
}
示例12: getClient
/**
* Return Google Content Client Instance
*
* @param int $storeId
* @param string $loginToken
* @param string $loginCaptcha
*
* @return Zend_Http_Client
*/
public function getClient($storeId, $noAuthRedirect = false)
{
$useServiceAccount = $this->getConfig()->getUseServiceAccount($storeId);
if (isset($this->_client)) {
if ($this->_client->isAccessTokenExpired()) {
if ($useServiceAccount) {
$client->getAuth()->refreshTokenWithAssertion();
} else {
return $this->redirectToAuth($storeId, $noAuthRedirect);
}
}
return $this->_client;
}
$adminSession = Mage::getSingleton('admin/session');
$accessTokens = $adminSession->getGoogleOAuth2Token();
$clientId = $this->getConfig()->getConfigData('client_id', $storeId);
$clientSecret = $this->getConfig()->getConfigData('client_secret', $storeId);
$clientEmail = $this->getConfig()->getConfigData('client_email', $storeId);
$privateKeyFile = Mage::getBaseDir() . self::PRIVATE_KEY_UPLOAD_DIR . $this->getConfig()->getConfigData('private_key_file', $storeId);
$privateKeyPassword = $this->getConfig()->getPrivateKeyPassword($storeId);
$privateKey = file_get_contents($privateKeyFile);
$credentials = new Google_Auth_AssertionCredentials($clientEmail, array('https://www.googleapis.com/auth/content'), $privateKey, $privateKeyPassword);
$accessToken = $accessTokens[$clientId];
if (!$clientId || !$clientSecret && !$useServiceAccount) {
Mage::getSingleton('adminhtml/session')->addError("Please specify Google Content API access data for this store!");
return false;
}
if (!$useServiceAccount) {
if (!isset($accessToken) || empty($accessToken)) {
return $this->redirectToAuth($storeId, $noAuthRedirect);
}
}
$client = new Google_Client();
$client->setApplicationName(self::APPNAME);
$client->setClientId($clientId);
$client->setScopes('https://www.googleapis.com/auth/content');
if ($useServiceAccount) {
$client->setClassConfig('Google_Cache_File', array('directory' => Mage::getBaseDir() . '/var/cache/bluevisiontec/googleshoppingapi/googleapi/'));
$client->setAssertionCredentials($credentials);
if ($client->getAuth()->isAccessTokenExpired()) {
$client->getAuth()->refreshTokenWithAssertion();
}
} else {
$client->setAccessToken($accessToken);
$client->setClientSecret($clientSecret);
if ($client->isAccessTokenExpired()) {
return $this->redirectToAuth($storeId, $noAuthRedirect);
}
}
$this->_client = $client;
return $this->_client;
}
示例13: exit
<?php
require_once 'config.php';
// Check given key
if (!array_key_exists("key", $_REQUEST)) {
exit("must provide authentication");
}
if (!array_key_exists($_REQUEST["key"], $keys)) {
exit("bad key");
}
// Checks have now passed, so load up the API client and start the instance
require __DIR__ . '/vendor/autoload.php';
// Compute engine auth
$client = new Google_Client();
$client->setAuth(new Google_Auth_AppIdentity($client));
$client->getAuth()->authenticateForScope('https://www.googleapis.com/auth/compute');
$client->setApplicationName("Ignition");
$client->setClassConfig('Google_Http_Request', 'disable_gzip', true);
$service = new Google_Service_Compute($client);
?>
<pre>
<?php
$reset = $service->instances->start($PROJECT_NAME, $ZONE, $keys[$_REQUEST["key"]]);
print_r($reset);
?>
</pre>
<?php
$results = $service->instances->getInstances();
print_r($results);
示例14: createClient
public static function createClient(array $config, $panelId)
{
$client = new Google_Client();
$client->setClassConfig('Google_Cache_File', 'directory', TMP);
$keyfile = $config['keyfile'];
if (strpos($keyfile, '/') !== 0) {
$keyfile = DOCROOT . '/' . $keyfile;
}
$key = @file_get_contents($keyfile);
if (!!$key) {
$cred = new Google_Auth_AssertionCredentials($config['email'], array(Google_Service_Analytics::ANALYTICS_READONLY), $key);
$client->setAssertionCredentials($cred);
if ($client->getAuth()->isAccessTokenExpired()) {
$client->getAuth()->refreshTokenWithAssertion($cred);
}
}
return $client;
}
示例15: setAppConfig
function setAppConfig($approval = 'auto')
{
$this->client = new Google_Client();
/* Set Retries */
$this->client->setClassConfig('Google_Task_Runner', 'retries', 5);
$this->userInfoService = new Google_Service_Oauth2($this->client);
$this->googleDriveService = new Google_Service_Drive($this->client);
$this->googleUrlshortenerService = new Google_Service_Urlshortener($this->client);
if (!empty($this->settings['googledrive_app_client_id']) && !empty($this->settings['googledrive_app_client_secret'])) {
$this->client->setClientId($this->settings['googledrive_app_client_id']);
$this->client->setClientSecret($this->settings['googledrive_app_client_secret']);
} else {
$this->client->setClientId('538839470620-fvjmtsvik53h255bnu0qjmbr8kvd923i.apps.googleusercontent.com');
$this->client->setClientSecret('UZ1I3I-D4rPhXpnE8T1ggGhE');
}
$this->client->setRedirectUri('http://www.florisdeleeuw.nl/use-your-drive/index.php');
$this->client->setApprovalPrompt($approval);
$this->client->setAccessType('offline');
$this->client->setScopes(array('https://www.googleapis.com/auth/drive', 'https://www.googleapis.com/auth/userinfo.email', 'https://www.googleapis.com/auth/userinfo.profile', 'https://www.googleapis.com/auth/urlshortener'));
$page = isset($_GET["page"]) ? '?page=' . $_GET["page"] : '';
$location = get_admin_url(null, 'admin.php' . $page);
$this->client->setState(strtr(base64_encode($location), '+/=', '-_~'));
/* Logger */
$this->client->setClassConfig('Google_Logger_File', array('file' => USEYOURDRIVE_CACHEDIR . '/log', 'mode' => 0640, 'lock' => true));
$this->client->setClassConfig('Google_Logger_Abstract', array('level' => 'debug', 'log_format' => "[%datetime%] %level%: %message% %context%\n", 'date_format' => 'd/M/Y:H:i:s O', 'allow_newlines' => true));
/* Uncomment the following line to log communcations.
* The log is located in /cache/log
*/
//$this->client->setLogger(new Google_Logger_File($this->client));
return true;
}