我已经使用ReactJS创建了一个Outlook加载项,并按照本指南获取了可以使用Outlook v2.0 REST API的令牌:https://docs.microsoft.com/en-us/office/dev/add-ins/outlook/use-rest-api
现在,我想开始使用Outlook Beta REST API,我认为可以使用相同的令牌来进行API调用,但是出现以下错误,提示我不能使用此令牌:
{"error":{"code":"UnableToReadToken","message":"OAuth token submitted with the request can not be parsed.","innerError":{"requestId":"b96fc800-82d4-4b6d-8aa0-0b9ff6a36873","date":"2020-02-21T09:27:27"}}}
反正有没有使用Office.context.mailbox.getCallbackTokenAsync
生成的令牌来调用此API?我知道我可能可以通过Azure AD获得oauth2令牌,但是在Azure AD Portal中,我没有适当的管理员访问权限来遵循此过程,因此我正在寻找不依赖于此的解决方案。
这是我的函数的代码段,用于获取令牌并调用API:
getToken() {
return new Promise(async function (resolve, reject) {
try {
Office.context.mailbox.getCallbackTokenAsync({ isRest: true }, function (result) {
if (result.status === "succeeded") {
let accessToken = result.value;
console.log(result.value);
resolve(accessToken);
} else {
console.log(result.status);
reject(result.status);
}
});
} catch (error) {
console.error(error);
reject(error);
}
})
}
getRules(token) {
return new Promise(async function (resolve, reject) {
try {
const url = 'https://outlook.office.com/api/beta/me/mailfolders/inbox/messagerules';
const header = new Headers({ 'Authorization': `Bearer ${token}` });
const options = {
headers: header
};
let response = await fetch(url, options);
let jsonResponse = await response.json();
console.log(jsonResponse);
resolve(jsonResponse);
} catch (error) {
console.error(error);
reject(error);
}
});
}
您提到没有适当的管理员访问权限才能使用AD v2身份验证终结点。
[目前有两种方法可以处理应用程序注册和用户授权。您是否确认,如果偶然地这些方法之一仍然可行...
使用Azure AD v2身份验证终结点:https://docs.microsoft.com/en-us/previous-versions/office/office-365-api/api/beta/use-outlook-rest-api-beta#RegAuthConverged
使用Azure Active Directory和OAuth:https://docs.microsoft.com/en-us/previous-versions/office/office-365-api/api/beta/use-outlook-rest-api-beta#RegAuthAzure
一些其他信息(您可能已经知道):
v2身份验证终结点已从Outlook和Outlook.com开发人员的预览状态提升为一般(GA)。
[如果您有使用Windows Live API来访问Outlook.com邮箱数据的生产中应用程序,则必须重写该应用程序以使用v2身份验证终结点和Outlook REST API。因为Outlook.com不推荐使用Windows Live API,并且Outlook.com用户启用了Outlook REST API的邮箱,所以这些用户在尝试运行此类Windows Live API应用程序时将出现HTTP 404错误。