如何解决在 IE11 中导入“@microsoft/microsft-graph-client”时出现语法错误
我使用 @azure/msal-browser
和 @azure/msal-react
进行身份验证。问题是当我添加 @microsoft/microsoft-graph-client
进行 Graph 调用时,它在 IE11 中失败。
我需要能够使用 PageIterator 和 Client 来获取我的其余联系人,不幸的是,由于此模块,IE11 无法加载。如果我在没有模块的情况下拨打电话,我只会得到前 100 个联系人,我需要所有联系人。任何帮助将不胜感激。
这是我的代码
import { PageIterator,Client } from '@microsoft/microsoft-graph-client';
import { loginRequest,graphConfig } from "../authConfig";
import { msalInstance } from "../index";
function getAuthenticatedClient (accessToken) {
const client = Client.init({
authProvider: (done) => {
done(null,accessToken.accessToken);
}
});
return client;
};
export async function getContactList() {
const account = msalInstance.getActiveAccount();
if (!account) {
throw Error("No active account! Verify a user has been signed in and setActiveAccount has been called.");
}
const response = await msalInstance.acquireTokenSilent({
...loginRequest,account: account
});
const headers = new Headers();
const bearer = `Bearer ${response.accessToken}`;
headers.append("Authorization",bearer);
const options = {
method: "GET",headers: headers
};
return fetch(graphConfig.graph + "/me/contacts",options)
.then(res => res.json())
.then(async (res) => {
let users = [],client = getAuthenticatedClient(response);
if (res["@odata.nextLink"]) {
let users = [];
let callBack = (data) => {
users.push(data);
return true;
};
let pageIterator = new PageIterator(client,res,callBack);
await pageIterator.iterate();
return users;
} else {
return res.value;
}
})
.catch(error => console.log(error));
};
export async function getOrgContactList() {
const account = msalInstance.getActiveAccount();
if (!account) {
throw Error("No active account! Verify a user has been signed in and setActiveAccount has been called.");
}
const response = await msalInstance.acquireTokenSilent({
...loginRequest,headers: headers
};
return fetch(graphConfig.graph + "/users",options)
.then(res => res.json())
.then(async(res) => {
let users = [],callBack);
await pageIterator.iterate();
return users;
} else {
return res.value;
}
})
.catch(error => console.log(error));
};
export async function emailData(data) {
const account = msalInstance.getActiveAccount();
if (!account) {
throw Error("No active account! Verify a user has been signed in and setActiveAccount has been called.");
}
const response = await msalInstance.acquireTokenSilent({
...loginRequest,bearer);
headers.append("Content-Type","application/json");
const options = {
method: "POST",headers: headers,body: JSON.stringify(data)
};
return fetch(graphConfig.graph + "/me/sendMail",options)
.then(res => res.json())
.then((res) => {
return res;
})
.catch(error => console.log(error));
};
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。