我已成功设置 Google Pub/Sub 以使用 Gmail API Watch 功能,如下所述:https ://developers.google.com/gmail/api/guides/push在我的 gmail 帐户中观看收件箱标签。
新消息到达后,我会立即收到有效格式的推送通知,例如:
{ message:
{ data: '.......',
attributes: {},
message_id: '1248700053943' },
subscription: '.....' }
在我 base64decode 数据后,我收到电子邮件和 historyId。然后,按照建议,我请求 gmail.users.history.list API(通过 API 控制台),并将 startHistoryId 设置为推送通知中的 historyId。然后得到没有任何细节的空响应:
GET https://www.googleapis.com/gmail/v1/users/me/history?startHistoryId=4658879&key={YOUR_API_KEY}
200 OK
- Show headers
{
"historyId": "4658894"
}
因此,通知中的 historyId 似乎无效。似乎 Gmail users.watch API 无法正常工作,并且发送了错误的 historyId,或者我只是遗漏了一些东西?