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


PHP Google_Client::refreshToken方法代码示例

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


在下文中一共展示了Google_Client::refreshToken方法的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: refreshToken

 public function refreshToken($accessToken)
 {
     $this->_googleClient->setAccessToken($accessToken);
     // Refresh the token if it's expired.
     if ($this->_googleClient->isAccessTokenExpired()) {
         $this->_googleClient->refreshToken($this->_googleClient->getRefreshToken());
     }
     return $this->_googleClient->getAccessToken();
 }
开发者ID:nissnac,项目名称:GettingStarted-Cloud,代码行数:9,代码来源:GoogleServices.php

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

示例4: create

 /**
  * @throws MissingConfigurationException
  * @return \Google_Client
  */
 public function create()
 {
     $client = new \Google_Client();
     $requiredAuthenticationSettings = array('applicationName', 'clientId', 'clientSecret', 'developerKey');
     foreach ($requiredAuthenticationSettings as $key) {
         if (!isset($this->authenticationSettings[$key])) {
             throw new MissingConfigurationException(sprintf('Missing setting "TYPO3.Neos.GoogleAnalytics.authentication.%s"', $key), 1415796352);
         }
     }
     $client->setApplicationName($this->authenticationSettings['applicationName']);
     $client->setClientId($this->authenticationSettings['clientId']);
     $client->setClientSecret($this->authenticationSettings['clientSecret']);
     $client->setDeveloperKey($this->authenticationSettings['developerKey']);
     $client->setScopes(array('https://www.googleapis.com/auth/analytics.readonly'));
     $client->setAccessType('offline');
     $accessToken = $this->tokenStorage->getAccessToken();
     if ($accessToken !== NULL) {
         $client->setAccessToken($accessToken);
         if ($client->isAccessTokenExpired()) {
             $refreshToken = $this->tokenStorage->getRefreshToken();
             $client->refreshToken($refreshToken);
         }
     }
     return $client;
 }
开发者ID:neos,项目名称:neos-googleanalytics,代码行数:29,代码来源:ClientFactory.php

示例5: refreshConnect

 /**
  * Permet de reconnecté le compte Google si l'access_token n'est plus valide
  * @param User $user
  * @param bool $saveInSession
  * @return bool
  */
 protected function refreshConnect(User $user, $saveInSession = true)
 {
     $response = true;
     $session = new Session();
     $refreshToken = $user->getGoogleRefreshToken();
     if (null != $refreshToken) {
         try {
             $this->client->refreshToken($refreshToken);
             $newAccessToken = $this->getAccessToken();
             if ($saveInSession) {
                 $session->set('access_token', $newAccessToken);
             }
             $this->setAccessToken($newAccessToken);
         } catch (\Exception $e) {
             $response = false;
         }
     } else {
         $response = false;
     }
     if ($response === false) {
         // revoked access
         $this->disconnect($user);
     }
     return $response;
 }
开发者ID:GregHubs,项目名称:GestionRessources,代码行数:31,代码来源:GoogleServiceManager.php

示例6: add_google_client

 public function add_google_client()
 {
     $auth_config = $this->get_auth_config();
     if (!empty($auth_config)) {
         try {
             $client = new Google_Client();
             $client->setAuthConfig($this->get_auth_config());
             $client->addScope(Google_Service_Analytics::ANALYTICS_READONLY);
             $client->setAccessType('offline');
             $token = $this->get_token();
             if ($token) {
                 $client->setAccessToken($token);
             }
             if ($client->isAccessTokenExpired()) {
                 $refresh_token = $this->get_refresh_token();
                 if ($refresh_token) {
                     $client->refreshToken($refresh_token);
                     $this->update_token($client->getAccessToken());
                 }
             }
             $this->client = $client;
             $this->service = new Google_Service_Analytics($this->client);
         } catch (Exception $e) {
             $message = 'Google Analytics Error[' . $e->getCode() . ']: ' . $e->getMessage();
             $this->disconnect($message);
             error_log($message, E_USER_ERROR);
             return;
         }
     }
 }
开发者ID:hipmill,项目名称:toplytics,代码行数:30,代码来源:toplytics.php

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

示例8: __construct

 public function __construct()
 {
     $config_file = $_SERVER['HOME'] . '/' . self::CONFIG_FILE_NAME;
     if (file_exists($config_file)) {
         $config = json_decode(file_get_contents($config_file));
     }
     if (!$config) {
         throw new Exception(sprintf('Could not find or read the config file at ' . '%s. You can use the config.json file in the samples root as a ' . 'template.', $config_file));
     }
     $client = new Google_Client();
     $client->setApplicationName($config->applicationName);
     $client->setClientId($config->clientId);
     $client->setClientSecret($config->clientSecret);
     try {
         $client->refreshToken($config->refreshToken);
     } catch (Google_Auth_Exception $exception) {
         print str_repeat('*', 40);
         print "Your refresh token was missing or invalid, fetching a new one\n";
         $refresh_token = $this->getRefreshToken($client);
         $config->refreshToken = $refresh_token;
         file_put_contents($config_file, json_encode($config));
         print "Refresh token saved to your config file\n";
         print str_repeat('*', 40);
     }
     $this->merchant_id = $config->merchantId;
     $this->service = new Google_Service_ShoppingContent($client);
 }
开发者ID:jaanek,项目名称:googleads-shopping-samples,代码行数:27,代码来源:BaseSample.php

示例9: onNextendYoutube

 function onNextendYoutube(&$google, &$youtube)
 {
     $config = new NextendData();
     $config->loadJson(NextendSmartSliderStorage::get(self::$_group));
     if (!class_exists('Google_Client')) {
         require_once dirname(__FILE__) . '/googleclient/Google_Client.php';
     }
     if (!class_exists('Google_YouTubeService')) {
         require_once dirname(__FILE__) . '/googleclient/contrib/Google_YouTubeService.php';
     }
     $google = new Google_Client();
     $google->setClientId($config->get('apikey', ''));
     $google->setClientSecret($config->get('apisecret', ''));
     $token = $config->get('token', null);
     if ($token) {
         $google->setAccessToken($token);
     }
     $youtube = new Google_YouTubeService($google);
     if ($google->isAccessTokenExpired()) {
         $token = json_decode($google->getAccessToken(), true);
         if (isset($token['refresh_token'])) {
             $google->refreshToken($token['refresh_token']);
             $config->set('token', $google->getAccessToken());
             NextendSmartSliderStorage::set(self::$_group, $config->toJSON());
         }
     }
 }
开发者ID:macconsultinggroup,项目名称:WordPress,代码行数:27,代码来源:youtube.php

示例10: refreshAuthToken

 private function refreshAuthToken(\Google_Client $client)
 {
     if ($client->isAccessTokenExpired()) {
         $client->refreshToken($client->getRefreshToken());
         file_put_contents(CREDENTIALS_FILE, $client->getAccessToken());
     }
 }
开发者ID:embracingelement,项目名称:bahai-community-site,代码行数:7,代码来源:CalendarClient.php

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

示例12: createByParams

 /**
  * Constructor for current class
  *
  * @param string $clientId
  * @param string $clientSecret
  * @param string $refreshToken
  * @return GMail
  */
 public static function createByParams($clientId, $clientSecret, $refreshToken)
 {
     $client = new \Google_Client();
     $client->setClientId($clientId);
     $client->setClientSecret($clientSecret);
     $client->addScope(\Google_Service_Gmail::MAIL_GOOGLE_COM);
     $client->refreshToken($refreshToken);
     return self::createByClient($client);
 }
开发者ID:victorholban,项目名称:codeception-gmail-api-module,代码行数:17,代码来源:GMail.php

示例13: loadByStaff

 /**
  * Load Google and Calendar Service data by Staff
  *
  * @param AB_Staff $staff
  * @return bool
  */
 public function loadByStaff(AB_Staff $staff)
 {
     $this->staff = $staff;
     if ($staff->get('google_data')) {
         try {
             $this->client->setAccessToken($staff->get('google_data'));
             if ($this->client->isAccessTokenExpired()) {
                 $this->client->refreshToken($this->client->getRefreshToken());
                 $staff->set('google_data', $this->client->getAccessToken());
                 $staff->save();
             }
             $this->service = new Google_Service_Calendar($this->client);
             return true;
         } catch (Exception $e) {
             $this->errors[] = $e->getMessage();
         }
     }
     return false;
 }
开发者ID:patrickcurl,项目名称:monks,代码行数:25,代码来源:AB_Google.php

示例14: get_login_token

 private function get_login_token()
 {
     $config = $this->config;
     $client = new Google_Client();
     $client->setClientId($config['client_id']);
     $client->setClientSecret($config['client_secret']);
     $client->setScopes($config['scope']);
     $client->refreshToken($config['refresh_token']);
     $token = $client->getAuth()->getAccessToken();
     return json_decode($token)->access_token;
 }
开发者ID:namgiangle90,项目名称:tokyobaito,代码行数:11,代码来源:ImageUpload.php

示例15: fetchAction

 public function fetchAction()
 {
     $em = $this->getDoctrine()->getEntityManager();
     // TODO move to a cron job
     // TODO move google credentials to symfony parameters file
     $configDirectories = array(__DIR__ . '/../Resources/config');
     $locator = new FileLocator($configDirectories);
     $clientSecret = $locator->locate('client_secret.json');
     $credentialsPath = $locator->locate('calendar-api-quickstart.json');
     // Get the API client and construct the service object.
     $client = new \Google_Client();
     $client->setApplicationName('Google Calendar API Quickstart');
     $client->setScopes(implode(' ', array(\Google_Service_Calendar::CALENDAR_READONLY)));
     $client->setAuthConfigFile($clientSecret);
     $client->setAccessType('offline');
     // Load previously authorized credentials from a file.
     if (file_exists($credentialsPath)) {
         $accessToken = file_get_contents($credentialsPath);
     } else {
         //TODO this should be accomplished with an error status
         return $this->render('TechlancasterWebBundle:Default:calendar.html.twig', array('message' => 'Invalid Credentials'));
     }
     $client->setAccessToken($accessToken);
     // Refresh the token if it's expired.
     if ($client->isAccessTokenExpired()) {
         $client->refreshToken($client->getRefreshToken());
         file_put_contents($credentialsPath, $client->getAccessToken());
     }
     $service = new \Google_Service_Calendar($client);
     $calendarId = '6l7e832ee9bemt1i9c42vltrug@group.calendar.google.com';
     $optParams = array('maxResults' => 29, 'orderBy' => 'startTime', 'singleEvents' => true, 'timeMin' => date('c'));
     $results = $service->events->listEvents($calendarId, $optParams);
     $events = array();
     $connection = $em->getConnection();
     $platform = $connection->getDatabasePlatform();
     $connection->executeUpdate($platform->getTruncateTableSQL('event', false));
     /**
      * @var $googleEvent Google_Service_Calendar_Event
      */
     foreach ($results->getItems() as $googleEvent) {
         $event = new Event();
         $event->setId($googleEvent->getId());
         $event->setDescription($googleEvent->getDescription());
         $event->setLocation($googleEvent->getLocation());
         $event->setStart(new \DateTime($googleEvent->getStart()->dateTime));
         $event->setEnd(new \DateTime($googleEvent->getEnd()->dateTime));
         $event->setSummary($googleEvent->getSummary());
         $em->persist($event);
         $events[] = $event;
     }
     $em->flush();
     return $this->render('TechlancasterWebBundle:Default:calendar.html.twig', array('message' => json_encode($events)));
 }
开发者ID:amayer5125,项目名称:tl-website,代码行数:53,代码来源:DefaultController.php


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