【发布时间】:2021-12-24 11:47:23
【问题描述】:
在使用特殊值“我”的情况之外,如何使用 userId 属性?
据我了解,当您使用“我”时,是指您已作为最终用户进行身份验证。
但是当您没有作为最终用户进行身份验证时,您不能使用“me”,也不能使用任何其他值,因为您没有执行给定请求的权限。
我试图了解如何在不使用 userId 字段中的值“me”的情况下代表经过身份验证的用户在我的应用上执行操作?
使用 Gmail nodeJs 客户端的示例:
const googleClient = new google.auth.OAuth2(client_id, client_secret, redirect_uri);
async function getUnreadEmailsFrom(userID) {
let gmail = google.gmail({ version: 'v1', auth: googleClient });
/* Here on the line below, I'd like to use the email or ID of an already authenticated user in order to perform a given action.
But the only way I understand that I am able to perform any action is by loading the token of the user and saving it via
googleClient.setCredentials(userToken)
and then using the special value 'me' inside the userId propery.
*/
let response = await gmail.users.messages.list({userId: 'me', q: 'is:unread', maxResults: 500 });
return response.data;
}
【问题讨论】:
-
你应该给出代码示例。
-
我刚刚添加了一个示例。谢谢。
-
您好,this 回答您的问题了吗?如果是这种情况,请考虑接受stackoverflow.com/help/someone-answers。
标签: node.js api google-api gmail-api