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


PHP Google_Client::setScopes方法代码示例

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


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

示例1: instantiateClient

 private function instantiateClient()
 {
     $this->client = new \Google_Client();
     $this->client->setApplicationName($this->config['applicationName']);
     $this->client->setAuthConfig($this->config['jsonFilePath']);
     $this->client->setScopes($this->config['scopes']);
 }
开发者ID:ozankurt,项目名称:google-core,代码行数:7,代码来源:Core.php

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

示例3: indexAction

 /**
  * @Route("/gatest2", name="front_ga2")
  *
  * @param Request $request
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function indexAction(Request $request)
 {
     $this->client = $this->get('GoogleClient');
     $this->client->setAuthConfig($this->getParameter('googleCredentialsFile'));
     $this->client->setApplicationName('Pingvin');
     $this->client->setScopes($this->getParameter('googleAnalyticsAuthUrl'));
     $this->analyticsService = $this->get('GoogleAnalyticsService');
     $accounts = $this->analyticsService->management_accounts->listManagementAccounts();
     $data = array();
     if (count($accounts->getItems()) > 0) {
         $items = $accounts->getItems();
         foreach ($items as $item) {
             $id = $item->getId();
             $properties = $this->analyticsService->management_webproperties->listManagementWebproperties($id);
             $items_e = $properties->getItems();
             foreach ($items_e as $item_e) {
                 $profiles = $this->analyticsService->management_profiles->listManagementProfiles($id, $item_e->getId());
                 $items_ee = $profiles->getItems();
                 foreach ($items_ee as $item_ee) {
                     $data[] = array($item_ee->getId(), $item_e->getId());
                 }
             }
         }
         var_dump('<pre>', $data);
     }
     return $this->render('CronBundle::message.html.twig', array('message' => '...'));
 }
开发者ID:jarold87,项目名称:pingvin,代码行数:33,代码来源:gaTest2.php

示例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');
 }
开发者ID:janusnic,项目名称:YoutubeAPI_Demo,代码行数:13,代码来源:GoogleLogin.php

示例5: init_youtube_service

 /**
  * Init all the youtube client service stuff.
  *
  * Instead of instantiating the service in the constructor, we delay
  * it until really neeed because it's really memory hungry (2MB). That
  * way the editor or any other artifact requiring repository instantiation
  * can do it in a cheap way. Sort of lazy loading the plugin.
  */
 private function init_youtube_service()
 {
     global $CFG;
     if (!isset($this->service)) {
         require_once $CFG->libdir . '/google/lib.php';
         $this->client = get_google_client();
         $this->client->setDeveloperKey($this->apikey);
         $this->client->setScopes(array(Google_Service_YouTube::YOUTUBE_READONLY));
         $this->service = new Google_Service_YouTube($this->client);
     }
 }
开发者ID:evltuma,项目名称:moodle,代码行数:19,代码来源:lib.php

示例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 = 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();
 }
开发者ID:EmmanuelYupit,项目名称:educursos,代码行数:21,代码来源:lib.php

示例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 = 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();
 }
开发者ID:janaece,项目名称:globalclassroom4_clean,代码行数:21,代码来源:lib.php

示例8: init_m27tube_service

 /**
  * Init all the m27tube client service stuff.
  *
  * Instead of instantiating the service in the constructor, we delay
  * it until really neeed because it's really memory hungry (2MB). That
  * way the editor or any other artifact requiring repository instantiation
  * can do it in a cheap way. Sort of lazy loading the plugin.
  */
 private function init_m27tube_service()
 {
     global $CFG;
     if (!isset($this->service)) {
         require_once $CFG->dirroot . '/repository/m27tube/google/lib.php';
         require_once $CFG->dirroot . '/repository/m27tube/google/Google/Service/YouTube.php';
         $this->client = get_google_client();
         $this->client->setDeveloperKey($this->apikey);
         $this->client->setScopes(array(Google_Service_YouTube::YOUTUBE_READONLY));
         $this->service = new Google_Service_YouTube($this->client);
     }
 }
开发者ID:moodletw,项目名称:moodle-repository_m27tube,代码行数:20,代码来源:lib.php

示例9: __construct

 /**
  * Sets the required params for authentication 
  * 
  * @param string $client_id our app's client id
  * @param string $client_secret our app's client secret 
  * @param string $redirect_uri where will the auth server send the client 
  * after generating an authorization code to authenticate
  * @param null|string $token token obtained when a code is authenticated
  * @param null|string $code response code to authenticate
  * @param null|array $scopes array of strings with OAuth2/google scopes 
  * to requested
  * @param null|Google_Client $client
  * @param bool $debug defaults to false
  */
 public function __construct($client_id, $client_secret, $redirect_uri, $token = null, $code = null, $scopes = null, $client = null, $debug = null)
 {
     $this->client_id = $client_id;
     $this->client_secret = $client_secret;
     $this->redirect_uri = $redirect_uri;
     $this->code = $code;
     $this->token = $token;
     if ($scopes !== null) {
         $this->scopes = $scopes;
     }
     if (is_bool($this->debug)) {
         $this->debug = $debug;
     } else {
         $this->debug = false;
     }
     if ($client === null) {
         $this->client = new Google_Client();
         $this->client->setClientId($this->client_id);
         $this->client->setClientSecret($this->client_secret);
         $this->client->setRedirectUri($this->redirect_uri);
         if ($token !== null) {
             $this->client->setAccessToken($token);
         }
         $this->client->setScopes($this->scopes);
     }
 }
开发者ID:elcodedocle,项目名称:gplusraffle,代码行数:40,代码来源:User.php

示例10: googleCallbackAction

 public function googleCallbackAction()
 {
     $response = array("status" => 0, "message" => "Thao tác không thành công");
     $code = $this->request->getPost("code", null, false);
     if ($code) {
         $google = new \Google_Client();
         $google->setApplicationName($this->config["GOOGLE_NAME"]);
         $google->setClientId($this->config["GOOGLE_ID"]);
         $google->setClientSecret($this->config["GOOGLE_SECRET"]);
         $google->setRedirectUri('postmessage');
         $scopes = array("https://www.googleapis.com/auth/userinfo.profile", "https://www.googleapis.com/auth/userinfo.email");
         $google->setScopes($scopes);
         $google->authenticate($code);
         $request = new \Google_Http_Request("https://www.googleapis.com/oauth2/v2/userinfo?alt=json");
         $userinfo = $google->getAuth()->authenticatedRequest($request);
         $response = $userinfo->getResponseBody();
         $userinfo = json_decode($response, true);
         $id = $userinfo["id"];
         $username = explode("@", $userinfo["email"]);
         $username = $username[0] . "_gg_" . $id;
         $data_user = array("email" => $userinfo["email"], "nickname" => $userinfo["name"], "username" => $username, "id" => $id);
         $response = $this->doSocialLogin($data_user);
     }
     echo json_encode($response);
     exit;
 }
开发者ID:nbtai,项目名称:haiquan,代码行数:26,代码来源:UserController.php

示例11: revokeAccessToken

 public static function revokeAccessToken()
 {
     $xmpData = erLhcoreClassModelChatConfig::fetch('xmp_data');
     $data = (array) $xmpData->data;
     try {
         if (isset($data['gtalk_client_token']) && $data['gtalk_client_token'] != '') {
             require_once 'lib/core/lhxmp/google/Google_Client.php';
             $client = new Google_Client();
             $client->setApplicationName('Live Helper Chat');
             $client->setScopes(array("https://www.googleapis.com/auth/googletalk", "https://www.googleapis.com/auth/userinfo.email"));
             $client->setClientId($data['gtalk_client_id']);
             $client->setClientSecret($data['gtalk_client_secret']);
             $client->setAccessType('offline');
             $client->setApprovalPrompt('force');
             $token = $data['gtalk_client_token'];
             $client->setAccessToken($data['gtalk_client_token']);
             // Refresh token if it's
             if ($client->isAccessTokenExpired()) {
                 $tokenData = json_decode($token);
                 $client->refreshToken($tokenData->refresh_token);
                 $accessToken = $client->getAccessToken();
             }
             if ($accessToken = $client->getAccessToken()) {
                 $client->revokeToken();
             }
             unset($data['gtalk_client_token']);
             $xmpData->value = serialize($data);
             $xmpData->saveThis();
         }
         return true;
     } catch (Exception $e) {
         throw $e;
     }
 }
开发者ID:paisdelconocimiento,项目名称:glpi-smartcities,代码行数:34,代码来源:lhxmp.php

示例12: getClient

 /**
  * Return Google Content Client Instance
  *
  * @param int  $storeId
  * @param bool $noAuthRedirect
  *
  * @return bool|Google_Client
  */
 public function getClient($storeId, $noAuthRedirect = false)
 {
     if (isset($this->_client)) {
         if ($this->_client->isAccessTokenExpired()) {
             return $this->redirectToAuth($storeId, $noAuthRedirect);
         }
         return $this->_client;
     }
     $clientId = $this->getConfig()->getConfigData('client_id', $storeId);
     $clientSecret = $this->getConfig()->getClientSecret($storeId);
     $accessToken = $this->_getAccessToken($storeId);
     if (!$clientId || !$clientSecret) {
         Mage::getSingleton('adminhtml/session')->addError("Please specify Google Content API access data for this store!");
         return false;
     }
     if (!isset($accessToken) || empty($accessToken)) {
         return $this->redirectToAuth($storeId, $noAuthRedirect);
     }
     $this->_client = new Google_Client();
     $this->_client->setApplicationName(self::APPNAME);
     $this->_client->setClientId($clientId);
     $this->_client->setClientSecret($clientSecret);
     $this->_client->setScopes('https://www.googleapis.com/auth/content');
     $this->_client->setAccessToken($accessToken);
     if ($this->_client->isAccessTokenExpired()) {
         return $this->redirectToAuth($storeId, $noAuthRedirect);
     }
     if ($this->getConfig()->getIsDebug($storeId)) {
         $this->_client->setLogger(Mage::getModel('gshoppingv2/logger', $this->_client)->setStoreID($storeId));
     }
     return $this->_client;
 }
开发者ID:rsquarem,项目名称:MageGoogleShoppingApiV2,代码行数:40,代码来源:GoogleShopping.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

function getClient()
{
    $client = new Google_Client();
    $client->setApplicationName(APPLICATION_NAME);
    $client->setScopes(SCOPES);
    $client->setAuthConfigFile(CLIENT_SECRET_PATH);
    $client->setAccessType('offline');
    $credentialsPath = CREDENTIALS_PATH;
    if (file_exists($credentialsPath)) {
        $accessToken = file_get_contents($credentialsPath);
    } else {
        $authUrl = $client->createAuthUrl();
        printf("Open the following link in your browser:\n%s\n", $authUrl);
        print 'Enter verification code: ';
        $authCode = trim(fgets(STDIN));
        $accessToken = $client->authenticate($authCode);
        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);
    if ($client->isAccessTokenExpired()) {
        $client->refreshToken($client->getRefreshToken());
        file_put_contents($credentialsPath, $client->getAccessToken());
    }
    return $client;
}
开发者ID:atsanna,项目名称:PHP-Custom-Floorplan-for-Domoticz,代码行数:29,代码来源:gcal.php

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


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