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


PHP Google_Client::loadServiceAccountJson方法代码示例

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


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

示例1: createClientFromJson

 /**
  * Create a configured Google Client ready for Datastore use, using the JSON service file from Google Dev Console
  *
  * @param $str_json_file
  * @return \Google_Client
  */
 public static function createClientFromJson($str_json_file)
 {
     $obj_client = new \Google_Client();
     $obj_client->setAssertionCredentials($obj_client->loadServiceAccountJson($str_json_file, [\Google_Service_Datastore::DATASTORE, \Google_Service_Datastore::USERINFO_EMAIL]));
     // App Engine php55 runtime dev server problems...
     $obj_client->setClassConfig('Google_Http_Request', 'disable_gzip', TRUE);
     return $obj_client;
 }
开发者ID:gonejack,项目名称:tumblr-images-datastore,代码行数:14,代码来源:GoogleAPIClient.php

示例2: create_client

 private function create_client()
 {
     $full_creds_file = $this->api_creds_file;
     if (!file_exists($full_creds_file)) {
         throw new \Exception("Cannot find file " . $full_creds_file, 1);
     }
     $client = new \Google_Client();
     echo "Credentials File: " . $full_creds_file . PHP_EOL;
     $cred = $client->loadServiceAccountJson($full_creds_file, array(\Google_Service_Analytics::ANALYTICS_READONLY));
     // Setup authentication to Google.
     // This is needed because we are running via a phar file
     $client->setClassConfig("Google_IO_Curl", ["options" => [CURLOPT_CAINFO => $this->pem_file]]);
     // re-auth if needed
     if ($client->getAuth()->isAccessTokenExpired()) {
         $client->getAuth()->refreshTokenWithAssertion($cred);
     }
     return $client;
 }
开发者ID:erickmarsh,项目名称:CacheWarmer,代码行数:18,代码来源:GoogleAnalytics.php

示例3: setGoogleServiceBigquery

 private function setGoogleServiceBigquery()
 {
     $client = new Google_Client();
     $client->setApplicationName($this->application_name);
     $client->setClientId($this->client_id);
     $key = file_get_contents('privatekey.p12');
     $cred = $client->loadServiceAccountJson($this->service_account_name, "https://www.googleapis.com/auth/bigquery");
     /*
     $cred = new Google_Auth_AssertionCredentials(
                     $this->service_account_name,
                     array('https://www.googleapis.com/auth/bigquery'),
                     $key);
     */
     $client->setAssertionCredentials($cred);
     if ($client->getAuth()->isAccessTokenExpired()) {
         $client->getAuth()->refreshTokenWithAssertion($cred);
         $service_token = $client->getAccessToken();
     }
     $this->service = new Google_Service_Bigquery($client);
     // Google_Service_Bigquery
 }
开发者ID:AmsterdamData,项目名称:Google,代码行数:21,代码来源:bigquery.php

示例4: date

<?php

include "vendor/autoload.php";
include "config.php";
$client = new Google_Client();
$credentials = $client->loadServiceAccountJson(__DIR__ . "/googlekeys.json", Google_Service_Calendar::CALENDAR_READONLY);
$client->setAssertionCredentials($credentials);
if ($client->getAuth()->isAccessTokenExpired()) {
    $client->getAuth()->refreshTokenWithAssertion();
}
$service = new Google_Service_Calendar($client);
// Print the next 10 events on the user's calendar.
$calendarId = CAL_ID;
$optParams = ['maxResults' => 15, 'orderBy' => 'startTime', 'singleEvents' => true, 'timeMin' => date('c')];
//$calendars = $service->calendarList->listCalendarList();
///** @type Google_Service_Calendar_Calendar $cal */
//foreach($calendars->getItems() as $cal) {
// var_dump($cal->getId());
//}
$results = $service->events->listEvents($calendarId, $optParams);
//var_dump($results->count());
$events = [];
/** @type Google_Service_Calendar_Event $event */
foreach ($results as $event) {
    //var_dump($event);
    //    var_dump($event->getSummary());
    $time = $event->getStart()->getDateTime() ? new DateTime($event->getStart()->getDateTime()) : new DateTime($event->getStart()->getDate());
    $start = $event->getStart()->getDateTime() ? $time->format('g:ia | D jS') : $time->format('D jS');
    $events[] = ['summary' => $event->getSummary(), 'start' => $start, 'end' => $event->getEnd()->getDateTime(), 'location' => $event->getLocation()];
}
header('Content-Type: application/json');
开发者ID:piogrek,项目名称:MagicMirror,代码行数:31,代码来源:calendar.php

示例5: testServiceAccountJson

 public function testServiceAccountJson()
 {
     $client = new Google_Client();
     $c = $client->loadServiceAccountJson(__DIR__ . "/testdata/service-12345.json", array());
     $this->assertInstanceOf('Google_Auth_AssertionCredentials', $c);
 }
开发者ID:sacredwebsite,项目名称:scalr,代码行数:6,代码来源:ApiClientTest.php

示例6: RuntimeException

 *
 * @license MIT
 * @author Mike Funk <mike@mikefunk.com>
 */
require __DIR__ . '/vendor/autoload.php';
use Google\Spreadsheet\DefaultServiceRequest;
use Google\Spreadsheet\ServiceRequestFactory;
use Google\Spreadsheet\SpreadsheetService;
use Google\Spreadsheet\Exception as SpreadsheetException;
// ensure we have a service account json file
if (!file_exists(__DIR__ . '/service_account.json')) {
    throw new RuntimeException('First download your service account json from the google developer ' . 'console into service_account.json');
}
// get the access token through the client
$client = new Google_Client();
$credentials = $client->loadServiceAccountJson(__DIR__ . '/service_account.json', $scopes = ['https://spreadsheets.google.com/feeds']);
$client->setAssertionCredentials($credentials);
if ($client->getAuth()->isAccessTokenExpired()) {
    $client->getAuth()->refreshTokenWithAssertion();
}
$response = json_decode($client->getAuth()->getAccessToken());
$accessToken = $response->access_token;
try {
    // bootstrap
    $serviceRequest = new DefaultServiceRequest($accessToken);
    ServiceRequestFactory::setInstance($serviceRequest);
    $spreadsheetService = new SpreadsheetService();
    // get the spreadsheet
    $spreadsheetFeed = $spreadsheetService->getSpreadsheets();
    // all spreadsheets
    // var_dump($spreadsheetFeed); exit;
开发者ID:NaszvadiG,项目名称:google-spreadsheets-test,代码行数:31,代码来源:index.php


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