如何将MS Graph API调用转换为GraphServiceClient方法调用?
查询另一个用户的日历的GraphServiceClient版本是什么?
var cal =等待_graphServiceClient。????? (请参阅下面的代码)
启动代码
builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddMicrosoftIdentityWebApi(builder.Configuration.GetSection("AzureAd"))
.EnableTokenAcquisitionToCallDownstreamApi()
.AddInMemoryTokenCaches();
var app = builder.Build();
剃须刀页面代码
using Microsoft.Graph;
using Microsoft.Identity.Web;
namespace MSGraphAPIPOC.Pages;
[Authorize]
[AuthorizeForScopes(Scopes = new[] { "Calendars.ReadWrite" })]
public class IndexModel : PageModel
{
private readonly ILogger<IndexModel> _logger;
private readonly GraphServiceClient _graphServiceClient;
public IndexModel(ILogger<IndexModel> logger, GraphServiceClient graphServiceClient)
{
_logger = logger;
_graphServiceClient = graphServiceClient;
}
public async Task OnGet()
{
...
https://graph.microsoft.com/v1.0/users/<calendarSMTP>/calendarview?startDateTime=2022-07-05T00:00:00&endDateTime=2022-07-05T23:59:00&select=start,end,subject
var cal = await _graphServiceClient.???? //What is the equivalent of the api call above?
...
}
}
任何帮助都将不胜感激。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有两种类型的MS Graph API权限,一个是
委托
,这意味着用户可以先登录,然后通过MS Graph API查询自己的信息。另一种类型是Application
,这意味着应用程序可以通过Graph API查询所有用户的信息。回到您的方案,您将Azure AD集成到您的ASP.NET Core Web应用程序中,这意味着用户必须先登录,然后访问
index
页面,对吗?因此,您现在使用委托
API许可,允许您使用等待_graphserviceclient.me.calendarview.request.request.request(queryOptions).getAsync().getAsync()日历视图,但没有许可来查询他人。
如果要查询其他人,则必须同意
application
API许可。在您的情况下, API 支持应用程序许可。然后在本节添加权限。然后使用下面的代码或此示例部分致电API:There are 2 types of ms graph api permission, one is
delegate
which means users can sign in first and then query their own information via ms graph api. Another type isApplication
, this means application can query all users' information via graph api.Come back to your scenario, you integrate azure ad into your asp.net core web application, which means users have to sign in first before then visit
Index
page right? So you are now using thedelegate
api permission, which allowing you to useawait _graphServiceClient.Me.CalendarView.Request( queryOptions ).GetAsync()
to query his/her own calendar view but don't have permission to query others.If you want to query others, you have to consent
application
api permission. In your scenario, the api supports application permission. Then following the screenshot in this section to add the permission. Then using code below or this sample section to call the api: