2

我从这里使用 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 示例代码?任何想法我做错了什么?

4

1 回答 1

0

如果 API Explorer 也无法正常工作,则表明您在 {my-app-id} 位置指定的项目 ID 不正确。它应该是一个已经创建好的项目。访问https://console.developers.google.com/home/dashboard?project={my-app-id}并确保您获得项目的仪表板。如果不是,那么这将确认项目 ID 不正确。

于 2015-11-29T21:14:09.467 回答