我正在尝试使用Outlook插件中生成的访问令牌来下载邮件附件,它引发了未经授权的错误(401)。看起来AccessToken无效。在生成插件后的5分钟内使用accessToken,以确保避免代码过期。
遵循Office documentation中建议的步骤并创建C#代码。我的代码摘要可用here:https://gist.github.com/rajeevprasanna/6b0ba1db1599500a94451958b4f52d79
我的加载项清单可用here,要求获得ReadWriteMailbox的许可:https://gist.github.com/rajeevprasanna/5ef93e3df80f304826742bb81a0b4421#file-addin-manifest-xml-L64
我正在Office365 Outlook WebClient上进行实验,但我必须研究一种适用于所有Outlook实例以及Office365和Exchange版本的统一解决方案。
根据建议的here提取访问令牌的代码:
let cb = (asyncResult) => {
console.log('asyncResult => '+ R.toString(asyncResult));
};
var options = {
isRest: true,
asyncContext: { message: 'Hello World!' }
};
Office.context.mailbox.getCallbackTokenAsync(options, cb);
在进行API调用时,将回调响应的值字段用作accessToken。 示例getCallbackTokenAsync响应:
{
"asyncContext": {
"message": "Hello World!"
},
"status": "succeeded",
"value": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6ImthME5Hb19aNUkwRms1MXpKblZjT2tHbzFvbyJ9.eyJzbXRwIjoic3JpbmlAeGVub3Z1cy1hbWVyaWNhbmEuY29tIiwidmVyIjoiRXhjaGFuZ2UuQ2FsbGJhY2suVjIiLCJhcHBpZCI6IjAwMDAwMDAyLTAwMDAtMGZmMS1jZTAwLTAwMDAwMDAwMDAwMCIsImRlcGxveW1lbnRpZCI6IiIsInRpZCI6Imhvc3RpbmdjbG91ZGFwcC5uZXQiLCJhY3IiOiIxIiwiYXBwaWRhY3IiOiIwIiwic2NwIjoiTWFpbC5SZWFkV3JpdGUgTWFpbC5TZW5kIENhbGVuZGFycy5SZWFkV3JpdGUgQ29udGFjdHMuUmVhZFdyaXRlIiwiaXNzIjoiMDAwMDAwMDItMDAwMC0wZmYxLWNlMDAtMDAwMDAwMDAwMDAwIiwiYXVkIjoiaHR0cHM6Ly93ZWJtYWlsLmhvc3RpbmdjbG91ZGFwcC5jb20iLCJleHAiOjE1NDI4NzcwMDMsIm5iZiI6MTU0Mjg3NjEwM30.c3sknGGbw1Jrip9Ke1AcLyRL-6VnWSSWTGrwmeo6Z7xwBfKD3ppNkSqb4cVZIzuV-8udQps2abQ9scPMn0DNRbFRUNlBfkhHUqR2_JHrMcMptL6ZqF-a7_-gOMcBSgNdUCk5mhGDJs9qiEiM47thv5HZC97k-aYZ-iyU8N-8SgMNDc8vjBdS2nPSKp6FgQfezmjxADT-mbflxNUIwUDfOAys2l8v_Qw30t3LDca2AMmHyK3GbEaXejdO4muzC-ZrRMUVThIfFsMs0x67E2aY--lxSwDmrfcEnXODW0_J72RtFNDV5wjxf1QH6-xfP0A34qbUlmVnjjiCeYCeCCtNEg"
}
经过一些跟踪并与示例project进行比较后,我发现错误似乎与权限类型为 ReadWriteMailbox 有关。如果使用权限类型 ReadItem 或 ReadWriteItem
完成查询,我就能提取附件