在Excel加载项中验证REST请求 [英] Authenticating a REST request in an Excel Add-in

查看:123
本文介绍了在Excel加载项中验证REST请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为Excel开发一个加载项,目标是它将基于电子表格中的数据创建日历事件.

I am trying to develop an add-in for Excel with the goal that it will create calendar events based on data inside a spreadsheet.

除了使用REST API在日历中构建事件外,我几乎可以做所有我想做的事情,而且我无法确切弄清楚哪里出了错.

I can do almost everything that I want except use the REST API to build the events in the calendar and I can't exactly figure out where I went wrong.

我已遵循文档由@MarcLaFleur 建议.

我可以毫无问题地构建和运行该应用程序,但是当我单击从OneDrive获取文件"按钮时,我得到以下信息:

I can build and run the application no problem, but when I click on the 'Get my files from OneDrive' button, I get the following:

Code: 5001
Message: An internal error has occurred.
name: Internal Error

这来自此函数else子句中公共目录中的program.js文件.

This is coming from the program.js file in the public directory somewhere in the else clause of this function.

function getDataWithoutAuthChallenge() {
    Office.context.auth.getAccessTokenAsync({ forceConsent: false },
        function (result) {
            if (result.status === "succeeded") {
                // TODO1: Use the access token to get Microsoft Graph data.
                accessToken = result.value;
                getData("/api/onedriveitems", accessToken);
            }
            else {
                console.log("Code: " + result.error.code);
                console.log("Message: " + result.error.message);
                console.log("name: " + result.error.name);
                document.getElementById("getGraphAccessTokenButton").disabled = true;
            }
        });
}

这是我的manifest.xml

    ...
    <WebApplicationInfo>
      <Id>c931b396-7 ... </Id>
      <Resource>api://localhost:3000/c931b396-7 ... </Resource>
      <Scopes>
        <Scope>files.read.all</Scope>
        <Scope>profile</Scope>
      </Scopes>
    </WebApplicationInfo>
  </VersionOverrides>

这是apps.dev.microsoft.com上的作用域:

如果您能为我提供帮助,那真的可以帮助我.

If you can shed any light for me, it would really help me out.

推荐答案

5001错误通常表明Office的加载项API发生了根本性的错误.例如,您的Office应用程序不支持API,清单不正确或office.js版本不兼容.由于您使用的是示例,因此请注意两点:

The 5001 error often suggests something fundamentally wrong with the add-in API in Office. For example, your Office app doesn't support the API, the manifest is incorrect, or the version of office.js doesn't work with it. Since you're using the sample, two things come to mind:

  1. 您没有运行最新的内部人员 构建
  2. 正在加载错误的清单(如果您正在 在Windows上并使用具有较旧版本的Visual Studio 2017 模式文件,因此您必须对调试进行构建后清理 清单XML)
  1. You aren't running the latest Insiders build
  2. The wrong manifest is getting loaded (this sometimes happens if you're on Windows and using a version of Visual Studio 2017 that has old schema files, so you have to do a post-build clean up of the debug Manifest XML)

尽管Rick对Scopes的评论是相关的,但清单和Azure注册看起来都不错. profile必须与openid一起使用(单独使用profile无效;单独使用openid无效),并且如上所述,您需要对此表示同意.作为开发人员,您可以尝试在协议级别上为您自己同意.您需要适当地更新client_id,redirect_uri和范围查询参数,并添加& prompt = consent.

Your manifest and Azure registration look mostly good, though Rick's comment about Scopes is relevant. profile must work with openid as a pair (profile alone won't work; openid alone won't work), and as discussed you need this consented. As the developer, you can try consenting for yourself at the protocol level. You’ll want to update the client_id, redirect_uri, and scope query parameters as appropriate, and add &prompt=consent.

这篇关于在Excel加载项中验证REST请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆