gpt4 book ai didi

azure - 如何以编程方式访问 Microsoft Office 365 Planner

转载 作者:行者123 更新时间:2023-12-03 00:27:17 24 4
gpt4 key购买 nike

我正在尝试使用 CSOM 和 Azure 应用程序访问 Microsoft Office 365 Planner。每当我尝试使用组 ID 访问规划器时,我都会收到以下错误:

401 - 未经授权:由于凭据无效,访问被拒绝。您无权使用您提供的凭据查看此目录或页面。

我已向 Azure Graph api 授予所需的权限。应用程序 - 读取全部组、读取和写入全部组。委派 - Tasks.ReadWrite

下面是我正在使用的示例代码:

//Querying plans in current group await 
graphClient.Groups[groupId].Planner.Plans.Request().GetAsync();

有什么选择可以实现这一目标吗?我需要访问规划器,并需要基于 Office 365 组创建存储桶和计划。

非常感谢任何帮助。提前致谢。

最佳答案

您应该使用 Microsoft Graph 而不是 Azure AD Graph API。

https://learn.microsoft.com/en-us/graph/planner-concept-overview

此外,您需要使用您的用户凭据进行身份验证才能访问 Planner。您可以更改 GetAccessToken 方法以通过这种方式进行身份验证(链接博客中的示例)。

private async Task<string> GetAccessToken(string resourceId, string userName, string password)
{
try
{
var authority = ConfigurationManager.AppSettings["ida:AuthorizationLoginUri"] + ConfigurationManager.AppSettings["ida:TenantId"];
var authContext = new AuthenticationContext(authority);
var credentials = new UserPasswordCredential(userName, password);
var authResult = await authContext.AcquireTokenAsync(resourceId, ConfigurationManager.AppSettings["ida:ClientIdNativeClient"], credentials);

// Get the result
return authResult.AccessToken;
}
catch (Exception ex)
{
// TODO: handle the exception
return;
}

您还需要确保您的应用已在门户中正确注册。请查看这个有用的博客,其中显示了如何克服您在访问规划器时所描述的错误: https://karinebosch.wordpress.com/2017/12/18/microsoft-graph/

关于azure - 如何以编程方式访问 Microsoft Office 365 Planner,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54534256/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com