Javascript 从Outlook加载项使用Outlook REST API测试版

Javascript 从Outlook加载项使用Outlook REST API测试版,javascript,outlook,outlook-web-addins,outlook-restapi,Javascript,Outlook,Outlook Web Addins,Outlook Restapi,我已使用ReactJS创建了一个outlook加载项,并按照本指南获取了一个能够使用outlook v2.0 REST API的令牌: 现在我想开始使用OutlookBetaREST API,我想我可以使用相同的令牌进行API调用,但是我得到以下错误,这表明我不能使用此令牌: {"error":{"code":"UnableToReadToken","message":"OAuth token submitted with the request can not be parsed.","inn

我已使用ReactJS创建了一个outlook加载项,并按照本指南获取了一个能够使用outlook v2.0 REST API的令牌:

现在我想开始使用OutlookBetaREST 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门户中,我没有适当的管理员权限来遵循此过程,因此我正在寻找一个不依赖于此的解决方案

以下是获取令牌和调用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身份验证终结点:

使用Azure Active Directory和OAuth:

... 一些附加信息(您可能已经知道):

对于Outlook和Outlook.com开发人员,v2身份验证终结点已从预览状态升级为一般可用(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错误


阅读此处的更多信息:

getCallbackTokenAsync提供的令牌不具有messagerules REST API调用所需的作用域。即使对于非测试版场景,此API也不应使用此令牌。