本文整理汇总了PHP中Google_Client::setAccessType方法的典型用法代码示例。如果您正苦于以下问题:PHP Google_Client::setAccessType方法的具体用法?PHP Google_Client::setAccessType怎么用?PHP Google_Client::setAccessType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Google_Client
的用法示例。
在下文中一共展示了Google_Client::setAccessType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionToken
public function actionToken()
{
//$this->checkAccess("token");
$client = new \Google_Client();
$client->setClientId(Yii::$app->params['OAUTH2_CLIENT_ID']);
$client->setClientSecret(Yii::$app->params['OAUTH2_CLIENT_SECRET']);
$client->setScopes('https://www.googleapis.com/auth/youtube');
//$redirect = filter_var('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'], FILTER_SANITIZE_URL);
$client->setRedirectUri(Yii::$app->params['redirectVideo']);
if (Yii::$app->request->get('code')) {
if (strval(Yii::$app->session->get('state')) !== strval(Yii::$app->request->get('state'))) {
die('The session state did not match.');
}
$client->authenticate(Yii::$app->request->get('code'));
if ($client->getAccessToken()) {
$token = $this->getToken();
$token->load(json_decode($client->getAccessToken(), true), "");
$token->save();
return ["token_saved" => $token];
}
return ["token_not_saved_code" => Yii::$app->request->get('code')];
}
if (!$client->getAccessToken()) {
// If the user hasn't authorized the app, initiate the OAuth flow
//$state = mt_rand();
$client->setState(Yii::$app->params['stateVideo']);
$client->setAccessType("offline");
$client->setApprovalPrompt("force");
Yii::$app->session->set('state', Yii::$app->params['stateVideo']);
$authUrl = $client->createAuthUrl();
return ["link" => $authUrl];
}
}
示例2: google
function google()
{
$client = new Google_Client();
$client->setApplicationName("snmmaurya");
$client->setClientId(CLIENT_ID);
$client->setClientSecret(CLIENT_SECRET);
$client->setRedirectUri(REDIRECT_URI);
$client->setApprovalPrompt(APPROVAL_PROMPT);
$client->setAccessType(ACCESS_TYPE);
$oauth2 = new Google_Oauth2Service($client);
if (isset($_GET['code'])) {
$client->authenticate($_GET['code']);
$_SESSION['token'] = $client->getAccessToken();
}
if (isset($_SESSION['token'])) {
$client->setAccessToken($_SESSION['token']);
}
if (isset($_REQUEST['error'])) {
echo '<script type="text/javascript">window.close();</script>';
exit;
}
if ($client->getAccessToken()) {
$user = $oauth2->userinfo->get();
$_SESSION['User'] = $user;
$_SESSION['token'] = $client->getAccessToken();
} else {
$authUrl = $client->createAuthUrl();
header('Location: ' . $authUrl);
}
}
示例3: 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;
}
示例4: __construct
/**
* @param \Google_Client $client
*/
public function __construct(\Google_Client $client)
{
$this->client = $client;
$this->client->setClientId(\Config::get('google.client_id'));
$this->client->setClientSecret(\Config::get('google.client_secret'));
$this->client->setDeveloperKey(\Config::get('google.api_key'));
$this->client->setRedirectUri(\Config::get('app.url') . "/loginCallback");
$this->client->setScopes(['https://www.googleapis.com/auth/youtube']);
$this->client->setAccessType('offline');
}
示例5: initializeClient
public function initializeClient()
{
$this->client = new Client();
$this->client->setAccessType('offline');
$this->client->setApplicationName('playlister');
$this->client->setClientId($this->config->get('services.youtube.client_id'));
$this->client->setClientSecret($this->config->get('services.youtube.client_secret'));
$this->client->setRedirectUri($this->config->get('services.youtube.redirect'));
$this->client->setDeveloperKey($this->config->get('services.youtube.api_key'));
$this->client->addScope('https://www.googleapis.com/auth/youtube.readonly');
if ($this->auth->check() && $this->request->session()->has('user.token')) {
$this->setToken($this->request->session()->get('user.token'));
}
}
示例6: 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;
}
示例7: 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;
}
}
}
示例8: changeAccessType
/**
* Change the access type of the calendar
*
* @param string $type
* @throws \KevinDitscheid\KdCalendar\Exception\AccessTypeNotSupportedException
*/
public function changeAccessType($type)
{
if ($type !== self::ACCESS_TYPE_ONLINE || $type !== self::ACCESS_TYPE_OFFLINE) {
throw new \KevinDitscheid\KdCalendar\Exception\AccessTypeNotSupportedException("The access type \"{$type}\" is not supported!", 1454959656);
}
$this->client->setAccessType($type);
}
示例9: create
/**
* @throws MissingConfigurationException
* @return \Google_Client
*/
public function create()
{
$client = new \Google_Client();
$requiredAuthenticationSettings = array('applicationName', 'clientId', 'clientSecret', 'developerKey');
foreach ($requiredAuthenticationSettings as $key) {
if (!isset($this->authenticationSettings[$key])) {
throw new MissingConfigurationException(sprintf('Missing setting "TYPO3.Neos.GoogleAnalytics.authentication.%s"', $key), 1415796352);
}
}
$client->setApplicationName($this->authenticationSettings['applicationName']);
$client->setClientId($this->authenticationSettings['clientId']);
$client->setClientSecret($this->authenticationSettings['clientSecret']);
$client->setDeveloperKey($this->authenticationSettings['developerKey']);
$client->setScopes(array('https://www.googleapis.com/auth/analytics.readonly'));
$client->setAccessType('offline');
$accessToken = $this->tokenStorage->getAccessToken();
if ($accessToken !== NULL) {
$client->setAccessToken($accessToken);
if ($client->isAccessTokenExpired()) {
$refreshToken = $this->tokenStorage->getRefreshToken();
$client->refreshToken($refreshToken);
}
}
return $client;
}
示例10: 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;
}
示例11: testSettersGetters
public function testSettersGetters()
{
$client = new Google_Client();
$client->setClientId("client1");
$client->setClientSecret('client1secret');
$client->setState('1');
$client->setApprovalPrompt('force');
$client->setAccessType('offline');
$client->setRedirectUri('localhost');
$client->setApplicationName('me');
$this->assertEquals('object', gettype($client->getAuth()));
$this->assertEquals('object', gettype($client->getCache()));
$this->assertEquals('object', gettype($client->getIo()));
$client->setAuth(new Google_Auth_Simple($client));
$client->setAuth(new Google_Auth_OAuth2($client));
try {
$client->setAccessToken(null);
die('Should have thrown an Google_Auth_Exception.');
} catch (Google_Auth_Exception $e) {
$this->assertEquals('Could not json decode the token', $e->getMessage());
}
$token = json_encode(array('access_token' => 'token'));
$client->setAccessToken($token);
$this->assertEquals($token, $client->getAccessToken());
}
示例12: getClient
function getClient()
{
$config = (include __DIR__ . '/ini.php');
$client = new Google_Client();
$client->setApplicationName("Webkameleon");
$client->setClientId($config['oauth2_client_id']);
$client->setClientSecret($config['oauth2_client_secret']);
$client->setRedirectUri($config['oauth2_redirect_uri']);
$client->setScopes($config['oauth2_scopes']);
$client->setState('offline');
$client->setAccessType('offline');
$client->setApprovalPrompt('force');
if (isset($_GET['code'])) {
$client->authenticate($_GET['code']);
die($client->getAccessToken());
} elseif (!isset($config['token'])) {
Header('Location: ' . $client->createAuthUrl());
} else {
$client->setAccessToken($config['token']);
if ($client->isAccessTokenExpired()) {
$token = json_decode($config['token'], true);
$client->refreshToken($token['refresh_token']);
}
}
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: revokeAccessToken
public static function revokeAccessToken()
{
$xmpData = erLhcoreClassModelChatConfig::fetch('xmp_data');
$data = (array) $xmpData->data;
try {
if (isset($data['gtalk_client_token']) && $data['gtalk_client_token'] != '') {
require_once 'lib/core/lhxmp/google/Google_Client.php';
$client = new Google_Client();
$client->setApplicationName('Live Helper Chat');
$client->setScopes(array("https://www.googleapis.com/auth/googletalk", "https://www.googleapis.com/auth/userinfo.email"));
$client->setClientId($data['gtalk_client_id']);
$client->setClientSecret($data['gtalk_client_secret']);
$client->setAccessType('offline');
$client->setApprovalPrompt('force');
$token = $data['gtalk_client_token'];
$client->setAccessToken($data['gtalk_client_token']);
// Refresh token if it's
if ($client->isAccessTokenExpired()) {
$tokenData = json_decode($token);
$client->refreshToken($tokenData->refresh_token);
$accessToken = $client->getAccessToken();
}
if ($accessToken = $client->getAccessToken()) {
$client->revokeToken();
}
unset($data['gtalk_client_token']);
$xmpData->value = serialize($data);
$xmpData->saveThis();
}
return true;
} catch (Exception $e) {
throw $e;
}
}
示例15: index
public function index()
{
//Config items added to global config file
$clientId = $this->config->item('clientId');
$clientSecret = $this->config->item('clientSecret');
$redirectUrl = $this->config->item('redirectUrl');
#session_start();
$client = new Google_Client();
$client->setClientId($clientId);
$client->setClientSecret($clientSecret);
$client->setRedirectUri($redirectUrl);
#$client->setScopes(array('https://spreadsheets.google.com/feeds'));
$client->addScope(array('https://spreadsheets.google.com/feeds'));
$client->addScope('email');
$client->addScope('profile');
$client->setApprovalPrompt('force');
//Useful if you had already granted access to this application.
$client->setAccessType('offline');
//Needed to get a refresh_token
$data['base_url'] = $this->config->item('base_url');
$data['auth_url'] = $client->createAuthUrl();
//Set canonical URL
$data['canonical'] = $this->config->item('base_url') . 'docs';
$this->load->view('docs', $data);
}