我正在尝试使用访问 token 从 Gmail API 获取 Gmail 搜索结果。
以下代码有效并返回我的电子邮件 ID 数组:
fetch(`https://www.googleapis.com/gmail/v1/users/${userId}/messages?access_token=${accessToken}`)
然后我尝试在 Gmail API documentation guidelines 之后附加一个搜索查询
fetch(`https://www.googleapis.com/gmail/v1/users/${userId}/messages?access_token=${accessToken}?q=${text}`)
它带来了这个错误 code: 401, message: 'Invalid Credentials'
身份验证范围设置为 https://mail.google.com/
,假定对电子邮件具有完全控制权。我尝试交换 access_token
和 q
参数,以及删除 access_token
参数,但仍然没有成功。我做错了什么?
最佳答案
`https://www.googleapis.com/gmail/v1/users/${userId}/messages?access_token=${accessToken}?q=${text}
您在此调用中执行 HTTP GET。使用 &
添加附加参数,只有第一个参数以 ?
试试这个:
`https://www.googleapis.com/gmail/v1/users/${userId}/messages?access_token=${accessToken}&q=${text}
关于http - 使用 API 和访问 token 的 Gmail 搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48644661/