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


PHP Google_Client::refreshTokenWithAssertion方法代碼示例

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


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

示例1: testFileCache

 public function testFileCache()
 {
     $this->onlyPhp55AndAbove();
     $this->checkServiceAccountCredentials();
     $client = new Google_Client();
     $client->useApplicationDefaultCredentials();
     $client->setScopes(['https://www.googleapis.com/auth/drive.readonly']);
     // filecache with new cache dir
     $cache = $this->getCache(sys_get_temp_dir() . '/cloud-samples-tests-php-cache-test/');
     $client->setCache($cache);
     $token1 = null;
     $client->setTokenCallback(function ($cacheKey, $accessToken) use($cache, &$token1) {
         $token1 = $accessToken;
         $cacheItem = $cache->getItem($cacheKey);
         // expire the item
         $cacheItem->expiresAt(new DateTime('now -1 second'));
         $cache->save($cacheItem);
         $cacheItem2 = $cache->getItem($cacheKey);
     });
     /* Refresh token when expired */
     if ($client->isAccessTokenExpired()) {
         $client->refreshTokenWithAssertion();
     }
     /* Make a service call */
     $service = new Google_Service_Drive($client);
     $files = $service->files->listFiles();
     $this->assertInstanceOf('Google_Service_Drive_FileList', $files);
     sleep(1);
     // make sure the token expires
     $client = new Google_Client();
     $client->useApplicationDefaultCredentials();
     $client->setScopes(['https://www.googleapis.com/auth/drive.readonly']);
     $client->setCache($cache);
     $token2 = null;
     $client->setTokenCallback(function ($cacheKey, $accessToken) use(&$token2) {
         $token2 = $accessToken;
     });
     /* Make another service call */
     $service = new Google_Service_Drive($client);
     $files = $service->files->listFiles();
     $this->assertInstanceOf('Google_Service_Drive_FileList', $files);
     $this->assertNotEquals($token1, $token2);
 }
開發者ID:jvidor,項目名稱:google-api-php-client,代碼行數:43,代碼來源:CacheTest.php

示例2:

// MUST be using composer
require_once '/var/www/relle/vendor/autoload.php';
session_start();
$client = new Google_Client();
// Name of proj in GoogleDeveloperConsole
$client->setApplicationName("relle-analytics");
// Generated in GoogleDeveloperConsole --> Credentials --> Service Accounts
$client->setAuthConfig('/var/www/relle/relle-analytics-3753dd041a88.json');
$client->addScope(Google_Service_Analytics::ANALYTICS_READONLY);
// Grab token if it's set
if (isset($_SESSION['service_token'])) {
    $client->setAccessToken($_SESSION['service_token']);
}
// Refresh if expired
if ($client->isAccessTokenExpired()) {
    $client->refreshTokenWithAssertion();
}
// Pin to Session
$_SESSION['service_token'] = $client->getAccessToken();
$myToken = $client->getAccessToken();
?>
{{Analytics::trackEvent('Página', 'Logs')}}
@extends ('layout.dashboard')

@section('page')
{{trans('interface.name', ['page'=>trans('log.title')])}}        
@stop

@section("title_inside")
{{trans('log.title')}}  
@stop
開發者ID:RExLab,項目名稱:relle,代碼行數:31,代碼來源:all.blade.php


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