问题
I am trying to develop an add-in for Microsoft Word Online. I am using Office.context.auth.getAccessTokenAsync
call to get access token of a user, but it throws
error: Object {
name: "API Not Supported",
message: "This browser does not support the requested API.",
code: 5009
}
status: "failed"
Can anyone help?
Here is code that I am using to get Token.
"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.");
}
}
})();
My manifest code placed above </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>
Also tried
<Resource>https://localhost:3000</Resource>
in above code.
来源:https://stackoverflow.com/questions/48666289/office-context-auth-getaccesstokenasync-throws-api-not-supported-while-developin