本文整理汇总了PHP中Google_Client::fetchAccessTokenWithAssertion方法的典型用法代码示例。如果您正苦于以下问题:PHP Google_Client::fetchAccessTokenWithAssertion方法的具体用法?PHP Google_Client::fetchAccessTokenWithAssertion怎么用?PHP Google_Client::fetchAccessTokenWithAssertion使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Google_Client
的用法示例。
在下文中一共展示了Google_Client::fetchAccessTokenWithAssertion方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getClient
function getClient()
{
// Authenticate your API Client
$client = new Google_Client();
//$client->addScope(Google_Service_Storage::DEVSTORAGE_FULL_CONTROL);
$client->addScope(Google_Service_Storage::DEVSTORAGE_READ_WRITE);
// see ~/sandbox/zouk-event-calendar/vendor/google/apiclient/src/Google/Service/Storage.php
$client->setAccessType("offline");
$client->useApplicationDefaultCredentials();
// no need to acquire special credentials
$token = $client->getAccessToken();
if (!$token) {
// this is always the case, and same access token is aquired in the fetch call below (can be printed)
//syslog(LOG_DEBUG, "girish: access token not present");
$token = $client->fetchAccessTokenWithAssertion();
$client->setAccessToken($token);
//syslog(LOG_DEBUG, $token['access_token']);
}
// token acquried above is always expired. and even if you run fetchAccess...Refreshtoken() it still stays expired
//if ($client->isAccessTokenExpired()) {
// //syslog(LOG_DEBUG, "girish: access token expired");
// $client->fetchAccessTokenWithRefreshToken($token);
//}
//if ($client->isAccessTokenExpired()) {
// syslog(LOG_DEBUG, "girish: access token still expired!"); // no idea how this works
//}
return $client;
}
示例2: elseif
} elseif (getenv('GOOGLE_APPLICATION_CREDENTIALS')) {
// use the application default credentials
$client->useApplicationDefaultCredentials();
} else {
echo missingServiceAccountDetailsWarning();
exit;
}
$client->setApplicationName("Sheets API Testing");
$client->setScopes(['https://www.googleapis.com/auth/drive', 'https://spreadsheets.google.com/feeds']);
// Some people have reported needing to use the following setAuthConfig command
// which requires the email address of your service account (you can get that from the json file)
// $client->setAuthConfig(["type" => "service_account", "client_email" => "my-service-account@developer.gserviceaccount.com"]);
// The file ID was copied from a URL while editing the sheet in Chrome
$fileId = '1zni9j6L5zqq05F0ZjMK3gag5CatyXW8B4riQaTkWpjM';
// Access Token is used for Steps 2 and beyond
$tokenArray = $client->fetchAccessTokenWithAssertion();
$accessToken = $tokenArray["access_token"];
// Section 1: Uncomment to get file metadata with the drive service
// This is also the service that would be used to create a new spreadsheet file
$service = new Google_Service_Drive($client);
$results = $service->files->get($fileId);
var_dump($results);
// Section 2: Uncomment to get list of worksheets
// $url = "https://spreadsheets.google.com/feeds/worksheets/$fileId/private/full";
// $method = 'GET';
// $headers = ["Authorization" => "Bearer $accessToken"];
// $httpClient = new GuzzleHttp\Client(['headers' => $headers]);
// $resp = $httpClient->request($method, $url);
// $body = $resp->getBody()->getContents();
// $code = $resp->getStatusCode();
// $reason = $resp->getReasonPhrase();
示例3: get_token
private function get_token()
{
$client = new Google_Client();
if ($credentials_file = $this->checkServiceAccountCredentialsFile()) {
$client->setAuthConfig($credentials_file);
} elseif (getenv('GOOGLE_APPLICATION_CREDENTIALS')) {
$client->useApplicationDefaultCredentials();
} else {
echo missingServiceAccountDetailsWarning();
exit;
}
$client->setApplicationName("IARD Tables");
$client->setScopes(array('https://spreadsheets.google.com/feeds'));
$token = $client->fetchAccessTokenWithAssertion();
return $token['access_token'];
}