microsoft-graph-api - 使用 Microsoft 图形 API 我想要用户个人资料照片
问题描述
嗨,我正在尝试获取用户照片,已使用
var tenantId = configuration.GetSection("AzureAd").GetSection("TenantId").Value;
var clientId = configuration.GetSection("AzureAd").GetSection("ClientId").Value;
var clientSecret = configuration.GetSection("AzureAd").GetSection("clientSecret").Value;
var InviteRedirectUrl = configuration.GetSection("AzureAd").GetSection("InviteRedirectUrl").Value;
var Instance = configuration.GetSection("AzureAd").GetSection("Instance").Value;
var URL = Instance + tenantId + "/v2.0";
var scopes = new string[] { "https://graph.microsoft.com/.default" };
var confidentialClient = ConfidentialClientApplicationBuilder
.Create(clientId)
.WithAuthority(URL)
.WithClientSecret(clientSecret)
.Build();
GraphServiceClient graphServiceClient =
new GraphServiceClient(new DelegateAuthenticationProvider(async (requestMessage) =>
{
var authResult = await confidentialClient
.AcquireTokenForClient(scopes)
.ExecuteAsync();
requestMessage.Headers.Authorization =
new AuthenticationHeaderValue("Bearer", authResult.AccessToken);
})
);
Stream photo = await graphServiceClient.Me.Photo.Content.Request().GetAsync();
我收到以下错误
代码:BadRequest 消息:当前经过身份验证的上下文对此请求无效。当向需要用户登录的端点发出请求时,就会发生这种情况。例如,/me 需要登录用户。代表用户获取令牌以向这些端点发出请求。对移动和本机应用程序使用 OAuth 2.0 授权代码流,对单页 Web 应用程序使用 OAuth 2.0 隐式流。内部错误:
如何解决?
解决方案
推荐阅读
- python - 尝试让 ezgmail 工作时出现 pydevconsole 错误。我怎样才能解决这个问题?
- java - 我怎样才能收到正确的网址?尝试从 Firebase 应用程序中的 googlesignin 帐户获取个人资料图片
- python - 将列表块写入文件,在块末尾添加换行符
- r - 如何将数据从 SQL 导入 data.table 格式?
- java - 如何在 android studio 中的活动之间共享数组列表?
- java - NoClassDefFoundError:org/w3c/dom/ls/DocumentLS - 在编译时修复后仅在部署时发生的问题
- snowflake-cloud-data-platform - 无法将变体值“”转换为 TIMESTAMP_NTZ
- java - 回收站视图显示为空而不是显示图像?
- python - 毫米:ss 格式的 PyQt 倒数计时器
- azure - Azure 语音识别未检测到麦克风 SPXERR_MIC_NOT_FOUND