【发布时间】:2021-03-17 00:05:21
【问题描述】:
我是 MS 图形 API 的新手。我正在学习这个 API,我遵循了这个教程https://docs.microsoft.com/en-us/azure/active-directory/develop/tutorial-v2-nodejs-console,它在检索用户时对我来说很好。这是代码
async function main() {
try {
// here we get an access token
const authResponse = await auth.getToken(auth.tokenRequest);
console.log("get auth reespones ", authResponse)
const options = {
method: 'get',
headers: {
Authorization: `Bearer ${authResponse}`
}
};
// call the web API with the access token
const users = await fetch.callApi(auth.apiConfig.uri, options);
console.log("get users ", users)
} catch (error) {
console.log("error here",error);
}
};
但我正在尝试调用其他 API,并且 我在访问日历 API 时遇到问题。 这是我用来在 ms graph 中调用日历 api 的新函数。
async function getcalendar() {
try {
// here we get an access token
const authResponse = await auth.getToken(auth.tokenRequest);
const options = {
method: 'get',
headers: {
Authorization: `Bearer ${authResponse}`,
Prefer: `outlook.timezone="Pacific Standard Time"`
}
}
// call the web API with the access token
const users = await fetch.callApi('https://graph.microsoft.com/v1.0/me/calendar', options);
console.log("get users ", users)
} catch (error) {
console.log("error is here ",error);
}
};
在我的天蓝色应用程序中,我已经设置了所有权限
感谢任何帮助。谢谢
【问题讨论】:
-
您使用的是个人帐号吗?
-
@ShivaKeshavVarma 是的,我是 ..
-
您好,如果发布的答案解决了您的问题,请单击复选标记将其标记为答案。这样做可以帮助其他人找到他们问题的答案。见meta.stackexchange.com/questions/5234/…
-
如何设置请求正文?
标签: microsoft-graph-api azure-ad-graph-api