当前位置: 首页>>代码示例>>PHP>>正文


PHP Google_Client::createAuthUrl方法代码示例

本文整理汇总了PHP中Google_Client::createAuthUrl方法的典型用法代码示例。如果您正苦于以下问题:PHP Google_Client::createAuthUrl方法的具体用法?PHP Google_Client::createAuthUrl怎么用?PHP Google_Client::createAuthUrl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Google_Client的用法示例。


在下文中一共展示了Google_Client::createAuthUrl方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: 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;
 }
开发者ID:neocodesoftware,项目名称:NeoCode-FmUsage,代码行数:38,代码来源:class.GoogleApi.php

示例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);
     }
 }
开发者ID:business-expert,项目名称:bellimodeling,代码行数:30,代码来源:google.php

示例3: 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

示例4: GoogleUser

 public function GoogleUser()
 {
     $client = new \Google_Client();
     $client->setApplicationName(\SKT_GOOGLEOAUTH2_SETAPPLICATIONNAME);
     // Visit https://code.google.com/apis/console?api=plus to generate your
     // oauth2_client_id, oauth2_client_secret, and to register your oauth2_redirect_uri.
     $client->setClientId(\SKT_GOOGLEOAUTH2_SETCLIENTID);
     $client->setClientSecret(\SKT_GOOGLEOAUTH2_SETCLIENTSECRET);
     $client->setRedirectUri(\SKT_GOOGLEOAUTH2_SETREDIRECTURI);
     $client->setDeveloperKey(\SKT_GOOGLEOAUTH2_SETDEVELOPERKEY);
     $oauth2 = new \Google_Oauth2Service($client);
     if (isset($_GET['code'])) {
         $client->authenticate($_GET['code']);
         $_SESSION['token'] = $client->getAccessToken();
         $redirect = \SITE_SERVER;
         \CmsDev\Header\refresh::refreshNow(\filter_var($redirect, FILTER_SANITIZE_URL));
         return;
     }
     if (isset($_SESSION['token'])) {
         $client->setAccessToken($_SESSION['token']);
     }
     if (isset($_REQUEST['logout']) or \THIS_URL_REAL === 'UserLogout') {
         unset($_SESSION['token']);
         $client->revokeToken();
     }
     if ($client->getAccessToken()) {
         $user = $oauth2->userinfo->get();
         // These fields are currently filtered through the PHP sanitize filters.
         // See http://www.php.net/manual/en/filter.filters.sanitize.php
         $this->family_name = filter_var($user['family_name'], \FILTER_SANITIZE_STRING);
         $this->name = filter_var($user['name'], \FILTER_SANITIZE_STRING);
         $this->locale = filter_var($user['locale'], \FILTER_SANITIZE_STRING);
         $this->gender = filter_var($user['gender'], \FILTER_SANITIZE_STRING);
         $this->email = filter_var($user['email'], \FILTER_SANITIZE_EMAIL);
         $this->link = filter_var($user['link'], \FILTER_SANITIZE_URL);
         $this->given_name = filter_var($user['given_name'], \FILTER_SANITIZE_STRING);
         $this->id = filter_var($user['id'], \FILTER_SANITIZE_STRING);
         $this->verified_email = filter_var($user['verified_email'], \FILTER_SANITIZE_STRING);
         if (isset($user['picture']) && $user['picture'] != '') {
             $this->picture = filter_var($user['picture'], \FILTER_VALIDATE_URL);
         } else {
             $this->picture = \SKT_ACCESS_AVATAR;
         }
         $this->ClientAuth = 'Google';
         $_SESSION['token'] = $client->getAccessToken();
         $this->createAuthUrl = $client->createAuthUrl();
         $this->Info = array('family_name' => HtmlSpecialChars($this->family_name), 'name' => HtmlSpecialChars($this->name), 'locale' => $this->locale, 'gender' => $this->gender, 'email' => $this->email, 'link' => $this->link, 'given_name' => HtmlSpecialChars($this->given_name), 'id' => $this->id, 'verified_email' => $this->verified_email, 'picture' => $this->picture, 'ClientAuth' => $this->ClientAuth, 'createAuthUrl' => $this->createAuthUrl);
         \CmsDev\Security\UserRegister::checkAction($this->Info);
         return true;
     } else {
         $this->createAuthUrl = $client->createAuthUrl();
         new \CmsDev\Url\refer();
         return false;
     }
 }
开发者ID:neruruguay,项目名称:neru,代码行数:55,代码来源:oauth.php

示例5: cmdLineAuth

 /**
  * Auth over command line
  */
 public function cmdLineAuth()
 {
     $authUrl = $this->client->createAuthUrl();
     //Request authorization
     print "Please visit:\n{$authUrl}\n\n";
     print "Please enter the auth code:\n";
     $authCode = trim(fgets(STDIN));
     // Exchange authorization code for access token
     $accessToken = $this->client->authenticate($authCode);
     $this->client->setAccessToken($accessToken);
     $this->accessToken = $accessToken;
     $this->refreshToken = $this->client->getRefreshToken();
 }
开发者ID:p13eater,项目名称:google-helper,代码行数:16,代码来源:GoogleHelper.php

示例6: getAuthURL

 /**
  * Returns a URL the user can visit to grant us permission to access their feed
  *
  * @return string
  */
 public function getAuthURL()
 {
     $state = mt_rand();
     $this->client->setState($state);
     Session::set($this->stateSessionIdentifier, $state);
     return $this->client->createAuthUrl();
 }
开发者ID:helpfulrobot,项目名称:littlegiant-silverstripe-youtubefeed,代码行数:12,代码来源:YouTubeFeed.php

示例7: getClient

function getClient()
{
    $client = new Google_Client();
    $client->setApplicationName(APPLICATION_NAME);
    $client->setScopes(SCOPES);
    $client->setAuthConfigFile(CLIENT_SECRET);
    $client->setAccessType('offline');
    // Load previously authorized credentials from a file.
    $credentialsPath = expandHomeDirectory(CREDENTIAL_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\n\t%s\n\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;
}
开发者ID:cmunky,项目名称:gcontact,代码行数:34,代码来源:gascapi.php

示例8: get

 public function get()
 {
     $callback = 'http://api.soundeavor.com/User/Auth/Login/Google/index.php';
     $config = new \Google_Config();
     $config->setApplicationName('Soundeavor');
     $config->setClientId(Config::getConfig('GoogleClientId'));
     $config->setClientSecret(Config::getConfig('GoogleClientSecret'));
     $config->setRedirectUri($callback);
     $client = new \Google_Client($config);
     /*
      * Add scopes (permissions) for the client https://developers.google.com/oauthplayground/
      */
     $client->addScope('https://www.googleapis.com/auth/plus.me');
     if (!isset($_GET['code'])) {
         $loginUrl = $client->createAuthUrl();
         header('Location: ' . $loginUrl);
     }
     $code = $_GET['code'];
     $client->authenticate($code);
     $accessToken = $client->getAccessToken();
     $accessToken = $accessToken['access_token'];
     $service = new \Google_Service_Plus($client);
     $scopes = $service->availableScopes;
     print_r($scopes);
     die;
 }
开发者ID:kris-nova,项目名称:API,代码行数:26,代码来源:Google.php

示例9: 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

示例10: 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;
}
开发者ID:podstawski,项目名称:appengine,代码行数:26,代码来源:google.php

示例11: getRedirectUri

 /**
  * This method is used to process the first part of authentication workflow, before redirect
  *
  * @return array Array with status and redirect URI
  */
 public function getRedirectUri()
 {
     $ngConnectINI = eZINI::instance('ngconnect.ini');
     $http = eZHTTPTool::instance();
     $clientID = trim($ngConnectINI->variable('LoginMethod_google', 'GoogleClientID'));
     if (empty($clientID)) {
         return array('status' => 'error', 'message' => 'Google client ID undefined.');
     }
     $callbackUri = self::CALLBACK_URI_PART;
     $loginWindowType = trim($ngConnectINI->variable('ngconnect', 'LoginWindowType'));
     if ($loginWindowType == 'popup') {
         $callbackUri = '/layout/set/ngconnect' . self::CALLBACK_URI_PART;
     }
     eZURI::transformURI($callbackUri, false, 'full');
     $state = md5(session_id() . (string) time());
     $http->setSessionVariable('NGConnectOAuthState', $state);
     $scope = self::SCOPE;
     $userScope = trim($ngConnectINI->variable('LoginMethod_google', 'Scope'));
     if (!empty($userScope)) {
         $scope = $userScope . ' ' . $scope;
     }
     $client = new Google_Client();
     $client->setApplicationName(trim($ngConnectINI->variable('LoginMethod_google', 'MethodName')));
     $client->setScopes($scope);
     $client->setClientId($clientID);
     $client->setRedirectUri($callbackUri);
     $client->setState($state);
     return array('status' => 'success', 'redirect_uri' => $client->createAuthUrl());
 }
开发者ID:netgen,项目名称:ngconnect,代码行数:34,代码来源:ngconnectauthgoogle.php

示例12: bdn_is_user_auth2

function bdn_is_user_auth2()
{
    global $driveService;
    $current_user_id = get_current_user_id();
    $client = new Google_Client();
    $client->setRedirectUri(home_url('/'));
    $driveService = new Google_DriveService($client);
    $oauth2 = new Google_Oauth2Service($client);
    if (!isset($_GET['code']) && (!is_user_logged_in() || ($access_token = get_user_meta($current_user_id, '_google_access_token', true)) && $client->setAccessToken($access_token) && !$client->getAccessToken())) {
        header('Location: ' . $client->createAuthUrl());
        exit;
    }
    if (isset($_GET['code'])) {
        $client->authenticate($_GET['code']);
        $user = $oauth2->userinfo->get();
        $new_user = get_user_by('email', $user['email']);
        if (!$current_user_id) {
            wp_set_current_user($new_user->ID, $new_user->user_login);
            wp_set_auth_cookie($new_user->ID);
            do_action('wp_login', $new_user->user_login);
        } elseif ($new_user->ID == $current_user_id) {
            update_user_meta($new_user->ID, '_google_access_token', $client->getAccessToken());
        } else {
            die('Sorry, please use your BDN account');
        }
        header('Location: http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']);
    }
    return $driveService;
}
开发者ID:bangordailynews,项目名称:Newsroom-Tools,代码行数:29,代码来源:gapi.php

示例13: 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']);
 }
开发者ID:Cloudrexx,项目名称:cloudrexx,代码行数:29,代码来源:Google.class.php

示例14: 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);
}
开发者ID:magical,项目名称:cs290-project,代码行数:29,代码来源:calendar.php

示例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);
 }
开发者ID:SaintGrey,项目名称:sheets2,代码行数:25,代码来源:docs.php


注:本文中的Google_Client::createAuthUrl方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。