【问题标题】:How to access Shared Mail Folder Using Microsoft Graph In .NET Application如何在 .NET 应用程序中使用 Microsoft Graph 访问共享邮件文件夹
【发布时间】:2019-01-17 07:21:45
【问题描述】:

我在 ASP.NET MVC 平台上生成了 Microsoft Graph 应用程序,我从 Microsoft Graph 站点下载了该应用程序。我需要访问共享邮件文件夹,但不确定我该如何获取??在下面的代码中,我可以访问我的 mailFolder,但不能访问共享的 mailfolder!

public static async Task<IEnumerable<MailFolder>> GetMailFolderAsync()
{
    var graphClient = GetAuthenticatedClient();
    var mailFolder = await graphClient.Me.MailFolders.Request().GetAsync();
    var sharedMailFolder = await graphClient.Users.Request().GetAsync();
    return mailFolder;
}

另外,我想知道在上面的代码中我可以在哪里传递参数来访问下一页或所有页面??

private static GraphServiceClient GetAuthenticatedClient()
    {
        return new GraphServiceClient(
            new DelegateAuthenticationProvider(
                async (requestMessage) =>
                {
                    string signedInUserId = ClaimsPrincipal.Current.FindFirst(ClaimTypes.NameIdentifier).Value;
                    SessionTokenStore tokenStore = new SessionTokenStore(signedInUserId,
                        new HttpContextWrapper(HttpContext.Current));

                    var idClient = new ConfidentialClientApplication(
                        appId, redirectUri, new ClientCredential(appSecret),
                        tokenStore.GetMsalCacheInstance(), null);

                    var accounts = await idClient.GetAccountsAsync();

                    var result = await idClient.AcquireTokenSilentAsync(
                        graphScopes.Split(' '), accounts.FirstOrDefault());

                    requestMessage.Headers.Authorization =
                        new AuthenticationHeaderValue("Bearer", result.AccessToken);
                }));

【问题讨论】:

    标签: asp.net-mvc microsoft-graph-api microsoft-graph-sdks


    【解决方案1】:

    我认为也无法访问我正在调查的共享文件夹。关于获取页面的问题,一收到第一个请求就可以了

    public static async Task<IEnumerable<MailFolder>> GetMailFolderAsync()
    {
        var graphClient = GetAuthenticatedClient();
        var mailFolder = await graphClient.Me.MailFolders.Request().GetAsync();
        var sharedMailFolder = await graphClient.Users.Request().GetAsync();
        return mailFolder;
    }
    

    然后您可以查看例如 mailFolder.NextPageRequest,如果它不为空,则可以通过执行 mailFolder.NextPageRequest.GetAsync() 来请求它,您可以将其用作循环条件

    while(mailfoldersCollection != null) {
    // Do your stuff with items within for(var folder in mailfoldersCollection) {}
    // when read all items in CurrentPage then
    if (mailFolder.NextPageRequest != null) {
    mailfoldersCollection = await mailFolder.NextPageRequest.GetAsync();
    }
    

    希望它对你有用!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多