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


PHP Google_Client::useApplicationDefaultCredentials方法代码示例

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


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

 /**
  * Setup correct auth method based on type.
  *
  * @param $userEmail
  * @return void
  */
 protected function auth($userEmail = '')
 {
     // see (and use) if user has set Credentials
     if ($this->useAssertCredentials($userEmail)) {
         return;
     }
     // fallback to compute engine or app engine
     $this->client->useApplicationDefaultCredentials();
 }
开发者ID:pulkitjalan,项目名称:google-apiclient,代码行数:15,代码来源:Client.php

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

示例4: __construct

 public function __construct($datastoreDatasetId)
 {
     $this->datasetId = $datastoreDatasetId;
     $client = new \Google_Client();
     $client->setScopes([Google_Service_Datastore::CLOUD_PLATFORM, Google_Service_Datastore::DATASTORE, Google_Service_Datastore::USERINFO_EMAIL]);
     $client->useApplicationDefaultCredentials();
     $this->datastore = new \Google_Service_Datastore($client);
 }
开发者ID:jjpeters67,项目名称:getting-started-php,代码行数:8,代码来源:Datastore.php

示例5: createAuthorizedClient

function createAuthorizedClient()
{
    $client = new Google_Client();
    $client->useApplicationDefaultCredentials();
    $client->addScope(Google_Service_Bigquery::BIGQUERY);
    $service = new Google_Service_Bigquery($client);
    return $service;
}
开发者ID:celialim,项目名称:php-docs-samples,代码行数:8,代码来源:util.php

示例6: __construct

 /**
  * CloudStorage constructor.
  *
  * @param string         $bucketName The cloud storage bucket name
  * @param \Google_Client $client     When null, a new Google_client is created
  *                                   that uses default application credentials.
  */
 public function __construct($bucketName, \Google_Client $client = null)
 {
     if (!$client) {
         $client = new \Google_Client();
         $client->useApplicationDefaultCredentials();
         $client->setApplicationName('php bookshelf');
         $client->setScopes(\Google_Service_Storage::DEVSTORAGE_READ_WRITE);
     }
     $this->service = new \Google_Service_Storage($client);
     $this->bucketName = $bucketName;
 }
开发者ID:jjpeters67,项目名称:getting-started-php,代码行数:18,代码来源:CloudStorage.php

示例7: Application

 */
use Google\Cloud\Samples\Datastore\DatastoreHelper;
use Silex\Application;
use Silex\Provider\TwigServiceProvider;
use Silex\Provider\UrlGeneratorServiceProvider;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
// create the silex application
$app = new Application();
$app->register(new TwigServiceProvider());
$app->register(new UrlGeneratorServiceProvider());
$app['twig.path'] = [__DIR__ . '/../templates'];
// create the google api client
$client = new Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope(Google_Service_Datastore::DATASTORE);
$client->addScope(Google_Service_Datastore::USERINFO_EMAIL);
// add the api client and project id to our silex app
$app['google_client'] = $client;
$app['project_id'] = getenv('GCP_PROJECT_ID');
$app->get('/', function () use($app) {
    /** @var Google_Client $client */
    $client = $app['google_client'];
    /** @var Twig_Environment $twig */
    $twig = $app['twig'];
    // run a simple query to retrieve the comments
    // - last 20 items ordered by created DESC
    $projectId = $app['project_id'];
    $datastore = new Google_Service_Datastore($client);
    $util = new DatastoreHelper();
开发者ID:JustinBeckwith,项目名称:php-docs-samples,代码行数:31,代码来源:app.php

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