我正在开发一个 Microsoft Graph API 应用程序,我想从收件箱中删除电子邮件。 为此,我首先获取电子邮件,将每封电子邮件的 id 放入一个数组中,然后为该数组中的每个 id 发出删除请求以将其从收件箱中删除。
当我尝试运行我的代码时,出现错误
Error: Server responded to *request link* with status code 403:
{
"error": {
"code": "ErrorAccessDenied",
"message": "Access is denied. Check credentials and try again.",
"innerError": {
"request-id": "*request id*",
"date": "2020-06-03T09:12:06"
}
}
}
在发出删除请求时,我传入了用于发出获取电子邮件数据的获取请求的相同访问 token 。
这是我的代码:
// This is only the code for the delete request, passing the Access Token works aswell as passing the IDList array. It loops trough all the id's and tries to make a request. But the request fails
removeEmail(IDList, AccessToken);
function removeEmail(idList, accessToken) {
idList.forEach(ID => {
var deleteEmails = request('DELETE', `https://graph.microsoft.com/v1.0/me/messages/${ID}`, {
headers: {
'Authorization': `Bearer ${accessToken}`
}
});
deletedEmails = JSON.parse(deleteEmails.getBody('utf8'));
console.log(deleteEmails);
});
}
如何解决此问题,以便从收件箱中删除邮件而不会出现任何问题?
提前致谢!
最佳答案
您向 Microsoft Graph API 应用添加了哪些权限?
删除电子邮件需要 Mail.ReadWrite
- https://learn.microsoft.com/en-us/graph/api/message-delete?view=graph-rest-1.0&tabs=http
另一方面,获取邮件列表需要以下权限 - Mail.ReadBasic、Mail.Read、Mail.ReadWrite
- https://learn.microsoft.com/en-us/graph/api/user-list-messages?view=graph-rest-1.0&tabs=http#permissions
为了能够阅读和删除电子邮件,您需要将 Mail.ReadWrite
添加到您的应用中。
关于node.js - Microsoft Graph API,DELETE 请求响应错误代码 403 ""访问被拒绝。检查凭据并重试。”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62169336/