我正在尝试为Microsoft Word Online开发一个加载项。我正在使用Office.context.auth.getAccessTokenAsync
调用来获取用户的访问令牌,但它会抛出
error: Object {
name: "API Not Supported",
message: "This browser does not support the requested API.",
code: 5009
}
status: "failed"
有人可以帮忙吗?
以下是我用来获取令牌的代码。
"use strict";
(function() {
// The initialize function is run each time the page is loaded.
Office.initialize = function(reason) {
$(document).ready(function() {
// Use this to check whether the API is supported in the Word client.
if (Office.context.requirements.isSetSupported("WordApi", 1.1)) {
// Do something that is only available via the new APIs
$("#buttonPressed").click(getToken);
} else {
// Just letting you know that this code will not work with your version of Word.
$("#supportedVersion").html("This code requires Word 2016 or greater.");
}
});
};
function getToken() {
if (Office.context.requirements.isSetSupported("IdentityAPI", 1.1)) {
console.log("Yes Identity API is supported");
// code to request an SSO token.
Office.context.auth.getAccessTokenAsync(function(result) {
if (result.status === "succeeded") {
var token = result.value.accessToken;
console.log(token);
} else {
console.log("Error obtaining token", result.error);
}
});
} else {
console.log(" ID API not supported.");
}
}
})();
我的清单代码位于</VersionOverrides>
<WebApplicationInfo>
<Id> <My App ID is here> </Id>
<Resource>api://localhost:3000/<My App ID is here></Resource>
<Scopes>
<Scope>Files.Read.All</Scope>
<Scope>offline_access</Scope>
<Scope>openid</Scope>
<Scope>profile</Scope>
</Scopes>
</WebApplicationInfo>
也试过
<Resource>https://localhost:3000</Resource>
在上面的代码中。