【发布时间】:2021-07-19 20:56:40
【问题描述】:
我正在尝试使用 PHP 创建发布/订阅通知。我有一个项目和一个服务帐户。我的代码如下:
use Google\Cloud\Core\Iam\PolicyBuilder;
use Google\Cloud\PubSub\PubSubClient;
use Google\Cloud\Storage\StorageClient;
self::$storage_client = new StorageClient(
[
'projectId' => "MY PROJECT ID",
'keyFile' => json_decode(file_get_contents("PATH TO MY KEYFILE", true)
]
);
$pubSub = new PubSubClient(
[ 'projectId' => "MY PROJECT ID"
);
$serviceAccountEmail = self::$storage_client->getServiceAccount();
$topicName = 'projects/MY PROJECT ID/topics/thumbnail-service-1';
$topic = $pubSub->topic( $topicName );
$iam = $topic->iam();
// --> Error happens here:
$updatedPolicy = (new PolicyBuilder( $iam->policy() ))
->addBinding('roles/pubsub.publisher', [ "serviceAccount:$serviceAccountEmail" ])
->result();
$iam->setPolicy( $updatedPolicy );
$notification = $bucket->createNotification( $topicName,
['event_types' => [
'OBJECT_FINALIZE',
'OBJECT_DELETE',
]
]
);
我想我正在尝试创建名为的主题,但我收到此错误:
exception 'Exception' with message 'exception 'Google\Cloud\Core\Exception\NotFoundException' with message '{
"error": {
"code": 404,
"message": "Resource not found (resource=thumbnail-service-1).",
"status": "NOT_FOUND"
}
}
它不应该试图找到主题,我想创建它。我错过了什么?
【问题讨论】:
标签: php google-cloud-storage google-cloud-pubsub