我从这里使用 PHP API 客户端库的 v1-master 分支: https://github.com/google/google-api-php-client/blob/v1-master/src/Google/Service/Pubsub。 php
我确定我所有的 OAuth 东西都是正确的,所以假设 $client 已经正确创建... {my-app-id} 也被替换为我的真实应用程序 ID
$pubsub = new Google_Service_Pubsub($client);
$new_topic = new Google_Service_Pubsub_Topic();
$new_topic->setName('projects/{my-app-id}/topics/mytopic');
$topic = $pubsub->topics->create($new_topic);
这会引发异常:
exception: Google_Service_Exception Object
(
[errors:protected] => Array
(
[0] => Array
(
[domain] => global
[reason] => invalidArgument
[message] => Invalid resource name given (name=projects/{my-app-id}/topics/mytopic). Refer to https://cloud.google.com/pubsub/overview#names for more information.
)
)
{my-app-id} 只是字母 az,因此它是有效的并且符合 pubsub 概述中的所有标准,并且我确实拥有该项目的权利,因为如果我更改 {my-app-id} 值,我会得到权限被拒绝消息。
我也浏览了 API Explorer 并得到了类似的错误结果:
要求:
PUT https://pubsub.googleapis.com/v1/projects/{my-app-id}/topics/mytopic?key={YOUR_API_KEY}
{
}
回复:
404 OK
- Show headers -
{
"error": {
"code": 404,
"message": "Requested entity was not found.",
"status": "NOT_FOUND"
}
}
我还尝试使用 API 客户端的主分支并将端点更改为 pubsub.googleapis.com/v1 端点而不是 www.googleapis.com/pubsub/v1beta1 ...我什至尝试了 v1beta2。没有任何工作。
我的项目启用了 PubSub API,但我无法创建任何主题。
有没有人有任何使用 PubSub 服务的工作应用程序的 PHP 示例代码?任何想法我做错了什么?