首页 > 解决方案 > 如何使用图形资源管理器 SDK?

问题描述

public class GraphService
{
    public async Task<dynamic> CreateGraphClient()
    {
        string clientId = "";
        string tenantID = "";
        string redirectUri = "http://localhost";
        //string clientSecret = "";
        string email = "myemail";
        SecureString password = new NetworkCredential("", "mypass").SecurePassword;

        string[] scopes = { "https://graph.microsoft.com/User.Read" };

        IPublicClientApplication publicClientApplication = PublicClientApplicationBuilder
                    .Create(clientId )
                    .WithTenantId(tenantID)
                    .Build();

        UsernamePasswordProvider authProvider = new UsernamePasswordProvider(publicClientApplication, scopes);

        GraphServiceClient graphClient = new GraphServiceClient(authProvider);

        User me = await graphClient.Me.Request()
             .WithUsernamePassword(email, password)
             .GetAsync();

        return me;
    }
}

NotSupportedException:不支持“Microsoft.Graph.User.AppRoleAssignments”上的集合类型“Microsoft.Graph.IUserAppRoleAssignmentsCollectionPage”。

标签: c#.netvisual-studio.net-coremicrosoft-graph-api

解决方案


推荐阅读