【发布时间】:2025-12-15 14:55:01
【问题描述】:
我想设置推送通知手表,但收到错误响应。我需要什么授权?
请求:
// Google API
$client = getClient();
// POST request
$ch = curl_init('https://www.googleapis.com/gmail/v1/users/me/watch');
curl_setopt_array($ch, array(
CURLOPT_POST => TRUE,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_HTTPHEADER => array(
'Authorization: Bearer ' . $client->getAccessToken()['access_token'],
'Content-Type: application/json'
),
CURLOPT_POSTFIELDS => json_encode(array(
'topicName' => 'projects/xxxx/topics/xxxx',
'labelIds' => ["INBOX"]
))
));
回复:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "forbidden",
"message": "Error sending test message to Cloud PubSub projects/xxxx/topics/xxxx : User not authorized to perform this action."
}
],
"code": 403,
"message": "Error sending test message to Cloud PubSub projects/xxxx/topics/xxxx : User not authorized to perform this action."
}
}
更多细节:
- 使用的范围是
GMAIL_READONLY。 - 订阅和主题存在并且它们是在同一个控制台中创建的。
- 我尝试从控制台发布一条新消息,它成功了。
【问题讨论】:
标签: php push-notification gmail gmail-api google-cloud-pubsub