本文整理汇总了PHP中Google_Client::setRedirectUri方法的典型用法代码示例。如果您正苦于以下问题:PHP Google_Client::setRedirectUri方法的具体用法?PHP Google_Client::setRedirectUri怎么用?PHP Google_Client::setRedirectUri使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Google_Client
的用法示例。
在下文中一共展示了Google_Client::setRedirectUri方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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);
}
}
示例2: __construct
/**
* Google constructor.
*/
public function __construct()
{
$this->_googleClient = new \Google_Client();
$this->_googleClient->setClientId(KACANA_SOCIAL_GOOGLE_KEY);
$this->_googleClient->setClientSecret(KACANA_SOCIAL_GOOGLE_SECRET);
$this->_googleClient->setApplicationName(KACANA_SOCIAL_GOOGLE_APP_NAME);
$this->_googleClient->setRedirectUri('postmessage');
}
示例3: __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);
}
示例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: __construct
/**
* Google
* @param $params array - data from config.neon
* @param $cookieName String cookie name
* @param Nette\Http\Response $httpResponse
* @param Nette\Http\Request $httpRequest
*/
public function __construct($params, $cookieName, Nette\Http\Response $httpResponse, Nette\Http\Request $httpRequest)
{
$this->params = $params;
$this->cookieName = $cookieName;
$this->httpResponse = $httpResponse;
$this->httpRequest = $httpRequest;
$this->client = new \Google_Client();
$this->client->setClientId($this->params["clientId"]);
$this->client->setClientSecret($this->params["clientSecret"]);
$this->client->setRedirectUri($this->params["callbackURL"]);
}
示例6: __construct
/**
* Constructor.
*
* @param int $repositoryid repository instance id.
* @param int|stdClass $context a context id or context object.
* @param array $options repository options.
* @param int $readonly indicate this repo is readonly or not.
* @return void
*/
public function __construct($repositoryid, $context = SYSCONTEXTID, $options = array(), $readonly = 0)
{
parent::__construct($repositoryid, $context, $options, $readonly = 0);
$callbackurl = new moodle_url(self::CALLBACKURL);
$this->client = get_google_client();
$this->client->setClientId(get_config('googledocs', 'clientid'));
$this->client->setClientSecret(get_config('googledocs', 'secret'));
$this->client->setScopes(array(Google_Service_Drive::DRIVE_READONLY));
$this->client->setRedirectUri($callbackurl->out(false));
$this->service = new Google_Service_Drive($this->client);
$this->check_login();
}
示例7: __construct
/**
* Constructor.
*
* @param int $repositoryid repository instance id.
* @param int|stdClass $context a context id or context object.
* @param array $options repository options.
* @param int $readonly indicate this repo is readonly or not.
* @return void
*/
public function __construct($repositoryid, $context = SYSCONTEXTID, $options = array(), $readonly = 0)
{
parent::__construct($repositoryid, $context, $options, $readonly = 0);
$callbackurl = new moodle_url(self::CALLBACKURL);
$this->client = new Google_Client();
$this->client->setClientId(get_config('googledocs', 'clientid'));
$this->client->setClientSecret(get_config('googledocs', 'secret'));
$this->client->setScopes(array('https://www.googleapis.com/auth/drive.readonly'));
$this->client->setRedirectUri($callbackurl->out(false));
$this->service = new Google_DriveService($this->client);
$this->check_login();
}
示例8: __construct
/**
* Google
* @param $params array - data from config.neon
* @param $cookieName String cookie name
* @param Nette\Http\Response $httpResponse
* @param Nette\Http\Request $httpRequest
*/
public function __construct($params, $cookieName, Nette\Http\Response $httpResponse, Nette\Http\Request $httpRequest)
{
$this->params = $params;
$this->cookieName = $cookieName;
$this->httpResponse = $httpResponse;
$this->httpRequest = $httpRequest;
$config = new \Google_Config();
$config->setClassConfig('Google_Cache_File', array('directory' => '/temp/cache'));
$this->client = new \Google_Client($config);
$this->client->setClientId($this->params["clientId"]);
$this->client->setClientSecret($this->params["clientSecret"]);
$this->client->setRedirectUri($this->params["callbackURL"]);
}
示例9: 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'));
}
}
示例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: 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;
}
示例12: authorizeGoogleUser
function authorizeGoogleUser($access_code)
{
$client = new \Google_Client();
$google = $this->config->google;
$client->setApplicationName('Portal da Rede');
$client->setClientId($google->clientId);
$client->setClientSecret($google->secret);
$client->setRedirectUri('postmessage');
$client->addScope('https://www.googleapis.com/auth/userinfo.profile');
$client->addScope('https://www.googleapis.com/auth/userinfo.email');
$client->authenticate($access_code);
$json_token = $client->getAccessToken();
$client->setAccessToken($json_token);
$plus = new \Google_Service_Plus($client);
$user = $plus->people->get('me');
if (!$user->emails || !is_array($user->emails)) {
return;
}
$email = $user->emails[0]['value'];
$user_email = $this->db->user_email->find_one($email);
if (!$user_email) {
return;
}
$this->login($user_email->user);
}
示例13: signin
public function signin()
{
$client = new \Google_Client();
$client->setClientId(Config::get('ntentan:social.google.client_id'));
$client->setClientSecret(Config::get('ntentan:social.google.client_secret'));
$client->setRedirectUri(Config::get('ntentan:social.google.redirect_uri'));
$client->addScope(array('profile', 'email'));
$oauth2 = new \Google_Service_Oauth2($client);
if (isset($_REQUEST['logout'])) {
Session::set('access_token', '');
$client->revokeToken();
}
if (isset($_GET['code'])) {
$client->authenticate($_GET['code']);
Session::set('access_token', $client->getAccessToken());
Redirect::path(\ntentan\Router::getRoute());
}
if (isset($_SESSION['access_token'])) {
$client->setAccessToken($_SESSION['access_token']);
}
if ($client->isAccessTokenExpired()) {
$authUrl = $client->createAuthUrl();
header('Location: ' . filter_var($authUrl, FILTER_SANITIZE_URL));
}
if ($client->getAccessToken()) {
$user = $oauth2->userinfo->get();
$_SESSION['token'] = $client->getAccessToken();
return array('firstname' => $user['given_name'], 'lastname' => $user['family_name'], 'key' => "google_{$user['id']}", 'avatar' => $user['picture'], 'email' => $user['email'], 'email_confirmed' => $user['verified_email']);
} else {
header("Location: {$client->createAuthUrl()}");
die;
}
return false;
}
示例14: flow
/**
* Google login method
* --
*/
public function flow()
{
$client = new Google_Client();
$client->setClientId($this->client_id);
$client->setClientSecret($this->client_secret);
$client->setRedirectUri($this->redirect_url);
$client->addScope("email");
$client->addScope("profile");
$this->context = Context::getContext();
$this->client = $client;
$this->service = new Google_Service_Oauth2($this->client);
if (Tools::getValue('code')) {
$this->client->authenticate(Tools::getValue('code'));
$this->context->cookie->__set('googleconnect_access_token', serialize($this->client->getAccessToken()));
Tools::redirect(filter_var($this->redirect_url, FILTER_SANITIZE_URL));
} else {
if ($this->context->cookie->__isset('googleconnect_access_token')) {
$a_token = unserialize($this->context->cookie->__get('googleconnect_access_token'));
$this->client->setAccessToken($a_token);
if (!$this->client->isAccessTokenExpired()) {
$this->context->cookie->__unset('googleconnect_access_token');
$this->loginToStore();
} else {
$this->setAuthUrl();
}
} else {
$this->setAuthUrl();
}
}
}
示例15: callback
public function callback()
{
$client = new Google_Client();
$client->setApplicationName($this->__app_name);
$client->setClientId($this->__client_id);
$client->setClientSecret($this->__client_secret);
$client->setRedirectUri($this->__redirect_uri);
$client->setDeveloperKey($this->__develop_key);
$client->setScopes('https://www.googleapis.com/auth/calendar');
$client->setAccessType('offline');
if (isset($_GET['code'])) {
$client->authenticate($_GET['code']);
$_SESSION['token'] = $client->getAccessToken();
$this->Session->delete('HTTP_REFERER');
header('Location: http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']);
}
// 呼び出し先
if (isset($_SESSION['oauth_referer'])) {
$url = $_SESSION['oauth_referer'];
$this->Session->delete('oauth_referer');
} else {
$url = 'index';
}
$this->redirect('/');
}