本文整理汇总了PHP中Google_Client::setIncludeGrantedScopes方法的典型用法代码示例。如果您正苦于以下问题:PHP Google_Client::setIncludeGrantedScopes方法的具体用法?PHP Google_Client::setIncludeGrantedScopes怎么用?PHP Google_Client::setIncludeGrantedScopes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Google_Client
的用法示例。
在下文中一共展示了Google_Client::setIncludeGrantedScopes方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例2: getClient
public static function getClient()
{
// $config = self::loadConfig();
$client = new Google_Client();
$client->setAuthConfigFile(dirname(__FILE__) . '/client_secret.json');
$client->setRedirectUri('http://' . $_SERVER['HTTP_HOST'] . FOLDER_APP);
$client->addScope(Google_Service_Gmail::MAIL_GOOGLE_COM);
$client->addScope(Google_Service_Gmail::GMAIL_COMPOSE);
$client->addScope(Google_Service_Gmail::GMAIL_MODIFY);
$client->addScope('http://www.google.com/m8/feeds/');
$client->addScope('https://www.googleapis.com/auth/userinfo.email');
$client->setIncludeGrantedScopes(true);
$client->setAccessType('offline');
$client->setApprovalPrompt('force');
return $client;
}
示例3: realpath
*/
error_reporting(E_ALL);
require_once realpath(dirname(__FILE__) . '/autoload.php');
$client = new Google_Client();
$client->setApplicationName("LyfeKit");
// optional
if ($request_from == 'web') {
$client_id = $_SERVER['HTTP_HOST'] == 'localhost:13080' ? "577040276233-jve4tho9nlqkhtr0gkjt9usmnksssar2.apps.googleusercontent.com" : "577040276233-uaf3iiujllb7dq49g96a80jsn1690dhg.apps.googleusercontent.com";
$client_secret = $_SERVER['HTTP_HOST'] == 'localhost:13080' ? "DFiFCKwiG5owtXIqMK04CW4N" : "ajEb8i843yMnsWiXBNCyExpT";
$redirect_uri = $_SERVER['HTTP_HOST'] == 'localhost:13080' ? 'http://localhost:13080' : 'http://lyfekit.com';
$client->setAccessType('offline');
/**
* Important: When your application receives a refresh token, it is important to store that refresh token for future use. If your application loses the refresh token, it will have to re-prompt the user for consent before obtaining another refresh token. If you need to re-prompt the user for consent, include the approval_prompt parameter in the authorization code request, and set the value to force.
*/
$client->setApprovalPrompt('auto');
$client->setIncludeGrantedScopes(TRUE);
} elseif ($request_from == 'mobile') {
$client_id = "577040276233-966074s939hj72put8bbbk9gac7gm4df.apps.googleusercontent.com";
$client_secret = "PVaezfl9npRfCOiuX4YA8iCb";
$redirect_uri = 'http://localhost';
$client->setAccessType('offline');
$client->setIncludeGrantedScopes(TRUE);
} else {
$this->print_error(array("status" => "error", "response" => "Invalid request from input"));
}
$client->setClientId($client_id);
$client->setClientSecret($client_secret);
$client->setRedirectUri($redirect_uri);
$client->addScope("https://www.googleapis.com/auth/plus.login");
$client->addScope("https://www.googleapis.com/auth/userinfo.email");
$client->addScope("https://www.googleapis.com/auth/userinfo.profile");
示例4: login
public function login($err = null)
{
$data = array();
$periodo_edicion = $this->evaluacion_model->getPeriodoEdicion();
if ($err != null) {
$data['err_msg'] = $err;
}
$email = $this->input->post('email');
if (!empty($email)) {
$password = $this->input->post('password');
$result = $this->user_model->do_login($email, $password);
if ($result) {
//var_dump($result->tipo);exit;
// Zona de permisos
$permisos = array('administrator' => $result->area == 4 && $result->tipo == 4 || $result->area == 26, 'create_requisicion' => in_array($result->tipo, array(4, 3)) || $result->nivel_posicion <= 5, 'requisicion_pendiente' => count($this->requisicion_model->getRequisicionesPendenting($result->id)));
//$_SESSION['access_token'] = 1;
$sess_array = array('id' => $result->id, 'nombre' => $result->nombre, 'email' => $result->email, 'foto' => $result->foto, 'empresa' => $result->empresa, 'posicion' => $result->nivel_posicion, 'area' => $result->area, 'direccion' => $result->direccion, 'tipo' => $result->tipo, 'periodo_edicion' => $periodo_edicion, 'permisos' => $permisos);
$data['email'] = $result->email;
$this->session->set_userdata($sess_array);
$re = "main/index";
} else {
$data['err_msg'] = "No es posible iniciar sesión, verifica las credenciales";
}
}
// Include two files from google-php-client library in controller
include_once APPPATH . "libraries/google-api-php-client-master/src/Google/autoload.php";
include_once APPPATH . "libraries/google-api-php-client-master/src/Google/Client.php";
include_once APPPATH . "libraries/google-api-php-client-master/src/Google/Service/Oauth2.php";
// Store values in variables from project created in Google Developer Console
$client_id = '904111204763-9c015hanptq9jehs8nj57at4joqfroe1.apps.googleusercontent.com';
$client_secret = '49DbvsMqY6-8dTCnlXJrIp-C';
$redirect_uri = base_url('auth');
$simple_api_key = 'AIzaSyBhG2aM8BVUvRNXRypylxu4XJBIYLWtdyQ';
// Create Client Request to access Google API
$client = new Google_Client();
$client->setApplicationName("Auth");
$client->setClientId($client_id);
$client->setClientSecret($client_secret);
$client->setRedirectUri($redirect_uri);
$client->setDeveloperKey($simple_api_key);
$client->addScope("https://www.googleapis.com/auth/userinfo.email");
$client->setIncludeGrantedScopes(true);
$client->setAccessType("offline");
// Send Client Request
$objOAuthService = new Google_Service_OAuth2($client);
// Add Access Token to Session
if (isset($_GET['code'])) {
$client->authenticate($_GET['code']);
$_SESSION['access_token'] = $client->getAccessToken();
$redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL));
}
// Set Access Token to make Request
if (isset($_SESSION['access_token']) && $_SESSION['access_token']) {
$client->setAccessToken($_SESSION['access_token']);
} else {
$authUrl = $client->createAuthUrl();
}
// Get User Data from Google and store them in $data
if ($client->getAccessToken()) {
if ($client->isAccessTokenExpired()) {
$authUrl = $client->createAuthUrl();
header('Location: ' . filter_var($authUrl, FILTER_SANITIZE_URL));
}
/*$NewAccessToken = json_decode($_SESSION['access_token']);
$client->refreshToken($NewAccessToken->access_token);*/
$userData = $objOAuthService->userinfo->get();
$email = $userData->email;
$result = $this->user_model->do_login($email);
if ($result) {
$_SESSION['access_token'] = $client->getAccessToken();
// Zona de permisos
$permisos = array('administrator' => ($result->area == 4 || $result->area == 26) && $result->tipo == 4, 'create_requisicion' => in_array($result->tipo, array(4, 3)) || $result->nivel_posicion <= 5, 'requisicion_pendiente' => count($this->requisicion_model->getRequisicionesPendenting($result->id)));
$sess_array = array('id' => $result->id, 'nombre' => $result->nombre, 'email' => $result->email, 'foto' => $result->foto, 'empresa' => $result->empresa, 'posicion' => $result->nivel_posicion, 'area' => $result->area, 'direccion' => $result->direccion, 'tipo' => $result->tipo, 'periodo_edicion' => $periodo_edicion, 'permisos' => $permisos);
$data['email'] = $result->email;
$this->session->set_userdata($sess_array);
} else {
echo "<script>alert('Credenciales Inválidas');</script>";
unset($_SESSION['access_token']);
}
$this->layout->title('Advanzer - Bienvenido');
$re = "main/index";
} else {
$authUrl = $client->createAuthUrl();
$data['authUrl'] = $authUrl;
$this->layout->title('Advanzer - Login');
$re = "main/login";
}
$this->verify_session();
// Load view and send values stored in $data
//$this->load->view('google_authentication', $data);
$this->layout->view($re, $data);
}
示例5:
//$client->addScope('https://docs.google.com/feeds');
//$client->authenticate($_GET['code']);
//$access_token = $client->getAccessToken();
//echo gettype($access_token) ;
//die($access_token);
//change to configurable
$access_token = '{
"access_token": "ya29.dALnYEH949dMsMb-pkHAmqVGwAPnsGf-D9gV4VexWxK4u69CRl_pK5jSzQv8L3XnpzfH",
"token_type": "Bearer",
"expires_in": 3600,
"created": 1453709814
}';
$client->setAccessToken($access_token);
$accessToken = json_decode($access_token);
if ($client->isAccessTokenExpired()) {
$client->setIncludeGrantedScopes(true);
$client->refreshToken($token->access_token);
$access_token = $client->getAccessToken();
// save the new token to configurable
$accessToken = json_decode($access_token);
}
$drive_service = new Google_Service_Drive($client);
$files_list = $drive_service->files->listFiles(array())->getItems();
/*foreach($files_list as $file){
/**
* @var Google_Service_Drive_DriveFile $file
*
*-/
echo $file->getId()."<br />\r\n";
echo $file->originalFilename."<br />\r\n";