我正在研究一个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"
}
}
}
当进行删除请求时,我传递了与我用于获取电子邮件数据的请求相同的访问令牌。
这是我的代码。
// 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:/docs.microsoft.comen-usgraphapimessag-delete?view=graph-rest-1.0&tabs=http。
另一方面,获取邮件列表的权限如下--------------------------。Mail.ReadBasic, Mail.Read, Mail.ReadWrite
- https:/docs.microsoft.comen-usgraphapiuser-list-messages?view=graph-rest-1.0&tabs=http#permissions
要想同时阅读和删除电子邮件,您需要具备以下条件 Mail.ReadWrite
添加到您的应用程序。