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


PHP Google_Client::fetchAccessTokenWithAssertion方法代码示例

本文整理汇总了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;
}
开发者ID:girishji,项目名称:zouk-event-calendar,代码行数:28,代码来源:common.php

示例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();
开发者ID:marcioyonamine,项目名称:igsisv1,代码行数:31,代码来源:google.php

示例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'];
 }
开发者ID:jhipwell6,项目名称:iard,代码行数:16,代码来源:google-functions.php


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