metglobal/gcp-rest-guzzle-adapter

此包已被弃用且不再维护。未建议替代包。

用于Google Cloud Platform REST端点的简单Guzzle适配器

v1.0.2 2017-05-15 12:00 UTC

This package is auto-updated.

Last update: 2023-11-20 19:16:51 UTC


README

用于Google Cloud Platform REST API的简单Guzzle适配器

用例

使用服务账户凭据(Google推荐的方式)访问Google Cloud Platform Rest API

有关认证的更多信息:https://cloud.google.com/speech/docs/common/auth

用法

use \GcpRestGuzzleAdapter\Client\ClientFactory;

// Service Account Email
$email = 'pubsub@test-project123.iam.gserviceaccount.com';

// Private Key
$key = '-----BEGIN PRIVATE KEY-----SDADAavaf...-----END PRIVATE KEY-----';

// Scope of Google Cloud Service
$scope = 'https://www.googleapis.com/auth/pubsub';

// Full base url of project
$projectBaseUrl = 'https://pubsub.googleapis.com/v1/projects/test-project123/';

$pubSubClient = ClientFactory::createClient($email, $key, $scope, $projectBaseUrl);

$result = $pubSubClient->get(
    sprintf('topics/%s/subscriptions', 'test-topic')
);

var_dump((string)$result->getBody()->getContents());
结果
string(113) "{
  "subscriptions": [
    "projects/test-project123/subscriptions/test_topicSubscriber"
  ]
}
"

要求

  • php >=5.6
  • guzzle 5.3
  • firebase/php-jwt 4.0
  • apc 或 apcu 用于令牌缓存(可注入自定义处理程序)