hprotravel / php-gcp-rest-client
Google Cloud Platform REST端点的简单Guzzle适配器
v0.4.1
2022-12-14 09:29 UTC
Requires
- php: ^7.2.5 || ^8.0
- ext-apcu: *
- ext-json: *
- firebase/php-jwt: 4.0
- guzzlehttp/guzzle: ^7.4
Requires (Dev)
- phpunit/phpunit: ^9.5
README
简单Guzzle适配器用于Google Cloud Platform REST API
用例
使用服务帐户凭证(谷歌推荐的方式)访问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: ^7.2.5 || ^8.0
- guzzlehttp/guzzle: ^7.4
- firebase/php-jwt: 4.0
- apc或apcu用于令牌缓存(也可注入自定义处理程序)