我已经使用yo office
命令创建了一个Outlook加载项项目。在其中,我尝试使用以下代码获取邮件列表:
// Get access token
Office.context.mailbox.getCallbackTokenAsync({isRest: true}, function(result){
if (result.status === "succeeded") {
var accessToken = result.value;
console.log('Access token : ' + accessToken);
} else {
console.log('Unable to get access token :(');
}
// Get item id
var itemId = Office.context.mailbox.convertToRestId(
Office.context.mailbox.item.itemId,
Office.MailboxEnums.RestVersion.v2_0
);
console.log('Item Id : ' + itemId);
// Get messages now
var messagesUrl = Office.context.mailbox.restUrl + 'v2.0/me/messages/' + itemId;
console.log('Querying url : ' + messagesUrl);
$.ajax({
url: messagesUrl,
dataType: 'json',
headers: { 'Authorization': 'Bearer ' + accessToken }
}).done(function(item){
console.log(item);
}).fail(function(error){
console.log(error);
});
});
问题在于,在运行插件时,出现以下错误:
SEC7120: Origin https://localhost:3000 not found in Access-Control-Allow-Origin header.
SCRIPT7002: XMLHttpRequest: Network Error 0x80070005, Access is denied.
任何帮助将不胜感激。清单文件中设置的权限为<Permissions>ReadWriteMailbox</Permissions>
答案 0 :(得分:0)
验证您在服务器上启用了CORS:
Access-Control-Allow-Origin: *
有关更多详细信息,请参见https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS。