tatilcom/gcp-rest-guzzle-adapter

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

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

This package is not auto-updated.

Last update: 2024-09-25 12:20:48 UTC


README

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

用例

使用服务账户凭证(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用于令牌缓存(也可以注入自定义处理程序)