本文整理汇总了PHP中Google_Client::setApprovalPrompt方法的典型用法代码示例。如果您正苦于以下问题:PHP Google_Client::setApprovalPrompt方法的具体用法?PHP Google_Client::setApprovalPrompt怎么用?PHP Google_Client::setApprovalPrompt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Google_Client
的用法示例。
在下文中一共展示了Google_Client::setApprovalPrompt方法的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: init
/**
* Initializes the Google Drive connection
*
* @param array $params Any connection params needed
* @return object
**/
public static function init($params = [])
{
// Get the params
$pparams = Plugin::params('filesystem', 'googledrive');
$app_id = isset($params['app_id']) && $params['app_id'] != '' ? $params['app_id'] : $pparams->get('app_id');
$app_secret = isset($params['app_secret']) && $params['app_secret'] != '' ? $params['app_secret'] : $pparams->get('app_secret');
$client = new \Google_Client();
$client->setClientId($app_id);
$client->setClientSecret($app_secret);
$client->addScope(Google_Service_Drive::DRIVE);
$client->setAccessType('offline');
$client->setApprovalPrompt('force');
$client->setIncludeGrantedScopes(true);
if (isset($params['app_token'])) {
$accessToken = $params['app_token'];
// json encode turned our array into an object, we need to undo that
$accessToken = (array) $accessToken;
} else {
\Session::set('googledrive.app_id', $app_id);
\Session::set('googledrive.app_secret', $app_secret);
\Session::set('googledrive.connection_to_set_up', Request::getVar('connection', 0));
// Set upp a return and redirect to Google for auth
$return = Request::getVar('return') ? Request::getVar('return') : Request::current(true);
$return = base64_encode($return);
$redirectUri = trim(Request::root(), '/') . '/developer/callback/googledriveAuthorize';
$client->setRedirectUri($redirectUri);
Session::set('googledrive.state', $return);
App::redirect($client->createAuthUrl());
}
$client->setAccessToken($accessToken);
$service = new \Google_Service_Drive($client);
$adapter = new \Hypweb\Flysystem\GoogleDrive\GoogleDriveAdapter($service, 'root');
return $adapter;
}
示例4: 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());
}
示例5: __construct
/**
* @param string $clientId
* @param string $clientSecret
* @param string $accessType
*/
public function __construct($clientId, $clientSecret, $accessType = 'offline')
{
$client = new \Google_Client();
// Get your credentials from the APIs Console
$client->setClientId($clientId);
$client->setClientSecret($clientSecret);
// Apparently you need to force to get refresh token
if ($accessType === 'offline') {
$client->setApprovalPrompt('force');
} else {
$client->setApprovalPrompt('auto');
}
$client->setAccessType($accessType);
$client->setRedirectUri('urn:ietf:wg:oauth:2.0:oob');
$this->client = $client;
}
示例6: 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);
}
示例7: 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;
}
示例8: login
/**
* Login to facebook and get the associated cloudrexx user.
*/
public function login()
{
$client = new \Google_Client();
$client->setApplicationName('Contrexx Login');
$client->setClientId($this->applicationData[0]);
$client->setClientSecret($this->applicationData[1]);
$client->setRedirectUri(\Cx\Lib\SocialLogin::getLoginUrl(self::OAUTH_PROVIDER));
$client->setDeveloperKey($this->applicationData[2]);
$client->setUseObjects(true);
$client->setApprovalPrompt('auto');
$client->setScopes(self::$scopes);
self::$google = new \Google_Oauth2Service($client);
self::$googleplus = new \Google_PlusService($client);
if (isset($_GET['code'])) {
try {
$client->authenticate();
} catch (\Google_AuthException $e) {
}
}
if (!$client->getAccessToken()) {
\Cx\Core\Csrf\Controller\Csrf::header('Location: ' . $client->createAuthUrl());
exit;
}
self::$userdata = $this->getUserData();
$this->getContrexxUser(self::$userdata['oauth_id']);
}
示例9: __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);
}
}
示例10: createAuthUrl
/**
* @param $staff_id
* @return string
*/
public function createAuthUrl($staff_id)
{
$this->client->setRedirectUri($this->generateRedirectURI());
$this->client->addScope('https://www.googleapis.com/auth/calendar');
$this->client->setState(strtr(base64_encode($staff_id), '+/=', '-_,'));
$this->client->setApprovalPrompt('force');
$this->client->setAccessType('offline');
return $this->client->createAuthUrl();
}
示例11: getClient
/**
* Returns an authorized API client.
*
* @return \Google_Client the authorized client object
*/
public function getClient()
{
$client = new \Google_Client();
$client->setApplicationName($this->applicationName);
$client->setScopes(implode(' ', $this->scopes));
$client->setAuthConfigFile($this->authConfigFile);
$client->setAccessType('offline');
$client->setApprovalPrompt('force');
return $client;
}
示例12: __construct
/**
* @param array $config
*/
public function __construct(array $config)
{
$this->config = $config;
// create an instance of the google client for OAuth2
$this->client = new \Google_Client();
// set application name
$this->client->setApplicationName(array_get($config, 'application_name', ''));
// set oauth2 configs
$this->client->setClientId(array_get($config, 'client_id', ''));
$this->client->setClientSecret(array_get($config, 'client_secret', ''));
$this->client->setRedirectUri(array_get($config, 'redirect_uri', ''));
$this->client->setScopes(array_get($config, 'scopes', []));
$this->client->setAccessType(array_get($config, 'access_type', 'online'));
$this->client->setApprovalPrompt(array_get($config, 'approval_prompt', 'auto'));
// set developer key
$this->client->setDeveloperKey(array_get($config, 'developer_key', ''));
// auth for service account
$this->auth();
}
示例13: _setGoogleClient
/**
*
*/
protected function _setGoogleClient()
{
$googleClient = new Google_Client();
$googleClient->setAuthConfigFile($this->_getConfigFilePath());
$googleClient->addScope($this->_getScopes());
$googleClient->setRedirectUri(Router::url(array('plugin' => 'auth_manager', 'controller' => 'media_platform_users', 'action' => 'callback', $this->_getPlatformId()), true));
// This will force Google to always return the refresh_token.
$googleClient->setAccessType('offline');
$googleClient->setApprovalPrompt('force');
$this->_client = $googleClient;
}
示例14: getGoogleClient
/**
* @return \Google_Client
*/
private function getGoogleClient()
{
if (null === self::$client) {
$container = $this->container;
$client = new \Google_Client();
$client->setClientId($container->getParameter('google_client_id'));
$client->setClientSecret($container->getParameter('google_client_secret'));
$client->setApprovalPrompt('auto');
self::$client = $client;
}
return self::$client;
}
示例15: getNewToken
function getNewToken()
{
$client = new Google_Client();
$client->setApplicationName(APPLICATION_NAME);
$client->setScopes(SCOPES);
$client->setAuthConfigFile(CLIENT_SECRET_PATH);
$client->setHostedDomain('email.wosc.edu');
$client->setAccessType('offline');
$client->setApprovalPrompt('force');
$client->setRedirectUri($GMAIL->callback);
$auth_url = $client->createAuthUrl();
header('Location: ' . filter_var($auth_url, FILTER_SANITIZE_URL));
}