本文整理汇总了PHP中Google_Client::setAuthConfigFile方法的典型用法代码示例。如果您正苦于以下问题:PHP Google_Client::setAuthConfigFile方法的具体用法?PHP Google_Client::setAuthConfigFile怎么用?PHP Google_Client::setAuthConfigFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Google_Client
的用法示例。
在下文中一共展示了Google_Client::setAuthConfigFile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getGoogleApiClient
/**
* Returns an authorized API client.
* @return Google_Client the authorized client object
*/
private function getGoogleApiClient()
{
$client = new Google_Client();
$client->setApplicationName($this->CFG['GOOGLE_API_APPLICATION_NAME']);
$client->setScopes(Google_Service_Calendar::CALENDAR);
$client->setAuthConfigFile($this->CFG['GOOGLE_API_CLIENT_SECRET_PATH']);
$client->setAccessType('offline');
// Load previously authorized credentials from a file.
$credentialsPath = $this->CFG['GOOGLE_API_CREDENTIALS_PATH'];
if (file_exists($credentialsPath)) {
$accessToken = file_get_contents($credentialsPath);
} 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->authenticate($authCode);
// Store the credentials to disk.
if (!file_exists(dirname($credentialsPath))) {
mkdir(dirname($credentialsPath), 0700, true);
}
file_put_contents($credentialsPath, $accessToken);
printf("Credentials saved to %s\n", $credentialsPath);
}
$client->setAccessToken($accessToken);
// Refresh the token if it's expired.
if ($client->isAccessTokenExpired()) {
$client->refreshToken($client->getRefreshToken());
file_put_contents($credentialsPath, $client->getAccessToken());
}
return $client;
}
示例2: getGoogleClient
private static function getGoogleClient($config)
{
$client = new \Google_Client();
$config = self::getGoogleConfig($config);
$client->setAuthConfigFile($config);
$userId = \HttpReceiver\HttpReceiver::get('userId', 'int');
if (!isset($userId)) {
$userId = \HttpReceiver\HttpReceiver::get('state', 'int');
}
$client->setRedirectUri($config['GOOGLEDRIVE_REDIRECT2']);
$client->addScope(\Google_Service_Drive::DRIVE);
return $client;
}
示例3: getClient
public static function getClient()
{
$creds = GoogleSessionController::getCreds();
$client = new Google_Client();
$env = Config::getEnvironment();
if ($env == 'local' && $creds->oauth_local_path) {
$client->setAuthConfigFile($creds->oauth_local_path);
} else {
if ($creds->oauth_remote_path) {
$client->setAuthConfigFile($creds->oauth_remote_path);
} else {
$client->setApplicationName($creds->app_name);
$client->setClientId($creds->client_id);
$client->setClientSecret($creds->client_secret);
}
}
$client->setRedirectUri(GoogleSessionController::getRedirectURI());
$hd = Config::get('config.google.hd');
if ($hd) {
$client->setHostedDomain($hd);
}
$client->setAccessType('offline');
$client->addScope("https://www.googleapis.com/auth/userinfo.profile");
$client->addScope("https://www.googleapis.com/auth/userinfo.email");
$client->setScopes($creds->scopes);
return $client;
}
示例4: __construct
public function __construct(\Google_Client $googleClient, $clientSecretPath)
{
$this->_googleClient = $googleClient;
$this->_googleClient->setAuthConfigFile($clientSecretPath);
$this->_googleClient->setRedirectUri('http://' . $_SERVER['HTTP_HOST'] . '/loginGoogle');
$this->_googleClient->addScope(\Google_Service_Gmail::GMAIL_READONLY);
$this->_gmailService = new \Google_Service_Gmail($this->_googleClient);
}
示例5: load_google_analytics
private function load_google_analytics()
{
WooCommerce_Grow::load_google_analytics();
// We setup the Google Client object
$this->client = new Google_Client();
$this->client->setAuthConfigFile(WooCommerce_Grow::get_plugin_path() . '\\ga-config.json');
$this->client->addScope(Google_Service_Analytics::ANALYTICS_READONLY);
$this->analytics = new Google_Service_Analytics($this->client);
}
示例6: __construct
/**
* GoogleServiceProvider constructor.
* @param $config
*/
public function __construct()
{
$this->client = new \Google_Client();
$this->projectName = config('google_cloud_storage.application');
$this->projectBucket = config('google_cloud_storage.bucket');
$this->authJsonFile = config('google_cloud_storage.auth_json_filename');
$this->client->setApplicationName($this->projectName);
$this->client->setAuthConfigFile(base_path($this->authJsonFile));
$this->client->addScope(\Google_Service_Storage::DEVSTORAGE_FULL_CONTROL);
}
示例7: __construct
/**
* GoogleServiceProvider constructor.
* @param $config
*/
public function __construct()
{
$this->client = new \Google_Client();
$this->projectName = config('google_pub_sub.application');
$this->authJsonFile = config('google_pub_sub.auth_json_filename');
$this->client->setApplicationName($this->projectName);
$this->client->setAuthConfigFile(base_path($this->authJsonFile));
//THIS IS NEEDED FOR CHROME ENV
//$this->client->useApplicationDefaultCredentials();
$this->client->addScope(Google_Service_Pubsub::PUBSUB);
}
示例8: 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);
}
示例9: getClient
function getClient()
{
$client = new Google_Client();
$client->setApplicationName(APPLICATION_NAME);
$client->setScopes(SCOPES);
$client->setAuthConfigFile(CLIENT_SECRET);
$client->setAccessType('offline');
// Load previously authorized credentials from a file.
$credentialsPath = expandHomeDirectory(CREDENTIAL_PATH);
if (file_exists($credentialsPath)) {
$accessToken = file_get_contents($credentialsPath);
} else {
// Request authorization from the user.
$authUrl = $client->createAuthUrl();
printf("Open the following link in your browser:\n\n\t%s\n\n", $authUrl);
print 'Enter verification code: ';
$authCode = trim(fgets(STDIN));
// Exchange authorization code for an access token.
$accessToken = $client->authenticate($authCode);
// Store the credentials to disk.
if (!file_exists(dirname($credentialsPath))) {
mkdir(dirname($credentialsPath), 0700, true);
}
file_put_contents($credentialsPath, $accessToken);
printf("Credentials saved to %s\n", $credentialsPath);
}
$client->setAccessToken($accessToken);
// Refresh the token if it's expired.
if ($client->isAccessTokenExpired()) {
$client->refreshToken($client->getRefreshToken());
file_put_contents($credentialsPath, $client->getAccessToken());
}
return $client;
}
示例10: getClient
/**
* Returns an authorized API client.
* @return Google_Client the authorized client object
*/
function getClient()
{
$client = new Google_Client();
$client->setApplicationName("Study Group Finder");
$client->setAuthConfigFile(__DIR__ . '/client_secret.json');
$client->addScope(Google_Service_Calendar::CALENDAR);
$client->setRedirectUri(current_url());
if (isset($_SESSION["googleauth"])) {
$client->setAccessToken($_SESSION["googleauth"]);
$_SESSION["googleauth"] = NULL;
return $client;
}
if (!isset($_GET['code'])) {
// Request authorization from the user.
$authUrl = $client->createAuthUrl();
header("Location: {$authUrl}");
exit(0);
}
$authCode = $_GET['code'];
// Exchange authorization code for an access token.
$accessToken = $client->authenticate($authCode);
$_SESSION["googleauth"] = $accessToken;
header("Location: calendar.php");
exit(0);
}
示例11: getClient
/**
* Returns an authorized API client.
* @return Google_Client the authorized client object
*/
function getClient()
{
global $credentialsPath;
$client = new Google_Client();
$client->setApplicationName(APPLICATION_NAME);
$client->setScopes(GAPI_SCOPES);
$client->setAuthConfigFile(CLIENT_SECRET_PATH);
$client->setAccessType('offline');
if (file_exists($credentialsPath)) {
$accessToken = file_get_contents($credentialsPath);
} else {
die("Please, get token via connect.php");
}
$client->setAccessToken($accessToken);
// Refresh the token if it's expired.
if ($client->isAccessTokenExpired()) {
$client = refreshToken($client);
}
return $client;
}
示例12: getClient
function getClient()
{
$client = new Google_Client();
$client->setApplicationName(APPLICATION_NAME);
$client->setScopes(SCOPES);
$client->setAuthConfigFile(CLIENT_SECRET_PATH);
$client->setAccessType('offline');
$credentialsPath = CREDENTIALS_PATH;
if (file_exists($credentialsPath)) {
$accessToken = file_get_contents($credentialsPath);
} else {
$authUrl = $client->createAuthUrl();
printf("Open the following link in your browser:\n%s\n", $authUrl);
print 'Enter verification code: ';
$authCode = trim(fgets(STDIN));
$accessToken = $client->authenticate($authCode);
if (!file_exists(dirname($credentialsPath))) {
mkdir(dirname($credentialsPath), 0700, true);
}
file_put_contents($credentialsPath, $accessToken);
printf("Credentials saved to %s\n", $credentialsPath);
}
$client->setAccessToken($accessToken);
if ($client->isAccessTokenExpired()) {
$client->refreshToken($client->getRefreshToken());
file_put_contents($credentialsPath, $client->getAccessToken());
}
return $client;
}
示例13: getClient
/**
* get google client
* @return Google_Client the authorized client object
*/
public static function getClient()
{
// $scopes = implode(' ', [Google_Service_Gmail::GMAIL_READONLY]);
/*
$scopes = [
'https://www.googleapis.com/auth/gmail.readonly',
'https://www.googleapis.com/auth/gmail.modify',
'https://www.googleapis.com/auth/gmail.send',
];
*/
$scopes = ['https://mail.google.com/'];
$clientSecretFile = conf('gmail.client_secret');
if (!file_exists($clientSecretFile)) {
pr('Error: client secret file not found', true);
pr('Please create "OAuth 2.0 client IDs"');
pr('login to https://console.developers.google.com/apis/credentials/');
exit;
}
$client = new Google_Client();
$client->setScopes($scopes);
$client->setAuthConfigFile($clientSecretFile);
$client->setAccessType('offline');
// $client->setApprovalPrompt('force');
$tokenFile = conf('gmail.access_token');
$accessToken = self::accessToken($client, $tokenFile);
$client->setAccessToken($accessToken);
// Refresh the token if it's expired.
if ($client->isAccessTokenExpired()) {
$client->refreshToken($client->getRefreshToken());
file_put_contents($tokenFile, $client->getAccessToken());
}
return $client;
}
示例14: getClient
function getClient()
{
$client = new Google_Client();
$client->setAuthConfigFile('includes/OAuth2/client_secret.json');
$client->setAccessToken($_SESSION['access_token']);
return $client;
}
示例15: __construct
public function __construct(\Google_Client $client)
{
$client->setApplicationName("magicpi");
$client->setScopes([\Google_Service_Calendar::CALENDAR_READONLY]);
$client->setAuthConfigFile(__DIR__ . "/../config/piauth.json");
$client->setAccessType('offline');
$client->setRedirectUri('http://' . $_SERVER['HTTP_HOST'] . '/auth');
$this->client = $client;
}