【发布时间】:2021-03-30 11:31:20
【问题描述】:
我收到以下错误:
代码:Request_ResourceNotFound
消息:资源“xxxx@xxxx.net”不存在或其查询的引用属性对象之一不存在。
我正在尝试使用图形 sdk 从我的 AD B2C 租户通过电子邮件检索用户,如下所示:
public static GraphServiceClient GetGraphServiceClient()
{
var clientapp = ConfidentialClientApplicationBuilder
.Create(Globals.ClientId)
.WithTenantId(Globals.TenantId)
.WithClientSecret(Globals.ClientSecret)
.Build();
ClientCredentialProvider authProvider = new ClientCredentialProvider(clientapp);
return new GraphServiceClient(authProvider);
}
public static async Task<User> GetADUserAsyncByEmail(string email)
{
var graphClient = GetGraphServiceClient();
try
{
var user = await graphClient.Users[email].Request().GetAsync();
return user;
}
catch(ServiceException ex)
{
return null;
}
catch( Exception ex)
{
return null;
}
}
【问题讨论】:
-
您尝试获取哪个用户电子邮件的详细信息?是个人账号还是工作账号?
标签: c# microsoft-graph-api azure-ad-b2c