當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Google_Client::addScope方法代碼示例

本文整理匯總了PHP中Google_Client::addScope方法的典型用法代碼示例。如果您正苦於以下問題:PHP Google_Client::addScope方法的具體用法?PHP Google_Client::addScope怎麽用?PHP Google_Client::addScope使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Google_Client的用法示例。


在下文中一共展示了Google_Client::addScope方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: 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;
 }
開發者ID:vanderlin,項目名稱:halp,代碼行數:27,代碼來源:GoogleSessionController.php

示例2: 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();
         }
     }
 }
開發者ID:garyconstable,項目名稱:prestashop-google-connect,代碼行數:34,代碼來源:login.php

示例3: 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);
 }
開發者ID:SaintGrey,項目名稱:sheets2,代碼行數:25,代碼來源:docs.php

示例4: call_back

 public function call_back()
 {
     $config = new Controllers_Api_Google_Config_App();
     $client = new Google_Client();
     $client->setClientId($config->config['client_id']);
     $client->setClientSecret($config->config['client_secret']);
     $client->setRedirectUri($config->config['redirect_uri']);
     $client->addScope("email");
     $client->addScope("profile");
     $service = new Google_Service_Oauth2($client);
     if (isset($_GET['code'])) {
         $client->authenticate($_GET['code']);
         $_SESSION['access_token'] = $client->getAccessToken();
         header('Location: ' . filter_var($config->config['redirect_uri'], FILTER_SANITIZE_URL));
         exit;
     }
     /************************************************
         If we have an access token, we can make
         requests, else we generate an authentication URL.
        ************************************************/
     if (isset($_SESSION['access_token']) && $_SESSION['access_token']) {
         $client->setAccessToken($_SESSION['access_token']);
     } else {
         $authUrl = $client->createAuthUrl();
     }
     if (isset($authUrl)) {
         //show login url
         echo json_encode(array('status' => false, 'data' => $authUrl));
     } else {
         $user = $service->userinfo->get();
         //get user info
         echo json_encode(array('status' => true, 'data' => $user));
     }
 }
開發者ID:anovanmaximuz,項目名稱:sosmed-cms,代碼行數:34,代碼來源:post.php

示例5: 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);
 }
開發者ID:kahvazquez,項目名稱:trouble,代碼行數:25,代碼來源:User.php

示例6: __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);
 }
開發者ID:nissnac,項目名稱:GettingStarted-Cloud,代碼行數:8,代碼來源:GoogleServices.php

示例7: 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);
 }
開發者ID:raisonon,項目名稱:woocommerce-grow,代碼行數:9,代碼來源:class-woocommerce-grow-google-analytics.php

示例8: __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);
 }
開發者ID:io-digital,項目名稱:google-cloud-storage,代碼行數:14,代碼來源:GoogleClient.php

示例9: __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);
 }
開發者ID:io-digital,項目名稱:google-pub-sub,代碼行數:15,代碼來源:GoogleClient.php

示例10: 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'));
     }
 }
開發者ID:JoeAlamo,項目名稱:Playlister,代碼行數:14,代碼來源:YoutubeAPIService.php

示例11: googleConnect

function googleConnect()
{
    require_once 'lib/Google/autoload.php';
    /* * *********************Google login************************ */
    $client = new Google_Client();
    $client->setClientId(CLIENT_ID);
    $client->setClientSecret(CLIENT_SECRET);
    $client->setRedirectUri(GOOGLE_REDIRECT_URI);
    $client->setAccessType('offline');
    $client->setApprovalPrompt('force');
    $client->addScope("openid email");
    $client->addScope("https://picasaweb.google.com/data/");
    $client->addScope("https://www.googleapis.com/auth/userinfo.profile");
    return $client;
}
開發者ID:shalinis34,項目名稱:Facebook-Albums,代碼行數:15,代碼來源:function.php

示例12: 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;
 }
開發者ID:ntentan,項目名稱:social-extension,代碼行數:34,代碼來源:GoogleSignin.php

示例13: 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;
 }
開發者ID:able-to-include,項目名稱:email-client,代碼行數:16,代碼來源:GoogleHelper.php

示例14: 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;
 }
開發者ID:kevinwojo,項目名稱:hubzero-cms,代碼行數:40,代碼來源:googledrive.php

示例15: googlecallback

 public function googlecallback()
 {
     $ret = null;
     //$google_redirect_url = site_url('user/signup');
     $google_redirect_url = 'http://localhost/punu/punu/index.php/user/signup';
     $client = new Google_Client();
     $client->setClientId($this->google_client_id);
     $client->setClientSecret($this->google_client_secret);
     $client->setDeveloperKey($this->google_api_key);
     $client->setRedirectUri($google_redirect_url);
     $client->addScope($this->google_scope);
     // Send Client Request
     $objOAuthService = new Google_Service_Oauth2($client);
     // Add Access Token to Session
     if (isset($_GET['code'])) {
         $client->authenticate($_GET['code']);
         $_SESSION['google_access_token'] = $client->getAccessToken();
         //header('Location: ' . filter_var($this->google_redirect_url, FILTER_SANITIZE_URL));
     }
     // Set Access Token to make Request
     if (isset($_SESSION['google_access_token']) && $_SESSION['google_access_token']) {
         $client->setAccessToken($_SESSION['google_access_token']);
     }
     // Get User Data from Google and store them in $data
     if ($client->getAccessToken()) {
         $userData = $objOAuthService->userinfo->get();
         //$_SESSION['userData'] = $userData;
         $_SESSION['google_access_token'] = $client->getAccessToken();
         $ret = $userData;
     }
     return $ret;
 }
開發者ID:arunmisra2273,項目名稱:punu,代碼行數:32,代碼來源:Plalib.php


注:本文中的Google_Client::addScope方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。