在成功上传清单之后,我现在正在努力使用Office JS API获取访问令牌。我跟踪了
the instructions
但目前为止运气不好。
我得到的错误是
13001 - the user is not signed in Office
. 但是,很明显,我已登录Office 365,因为我正在从Outlook Online运行加载项。
代码:
function showDialog() {
getDataWithToken({ forceConsent: false });
Office.context.ui.displayDialogAsync('https://localhost:3000/PluginApp/index.html',
{ height: 80, width: 80, displayInIframe: true}, function(asyncResult) {
// ... code
});
function getDataWithToken(options) {
Office.context.auth.getAccessTokenAsync(options,
function (result) {
debugger;
if (result.status === "succeeded") {
//TODO1: Use the access token to get Microsoft Graph data.
}
else {
handleClientSideErrors(result);
}
});
}
function handleClientSideErrors(result) {
switch (result.error.code) {
case 13001:
getDataWithToken({ forceAddAccount: true });
break;
}
}
打印屏幕如下:
其他答案:
2) 在我的清单文件中,我定义了ExecuteFunction,以便在用户单击addin时运行该方法。我没有使用任务窗格,因为宽度太小。我想打开一个对话框,以便有更多的空间来渲染这些东西。因此,我无法在对话框打开之前获取信息,因为我获取的可能是敏感信息,所以整个代码都是在打开对话框之后。
3) 我的公司使用主Office 365帐户。设置是混合的(本地AD邮箱和云邮箱。数据通过DirSync同步)。