Office 365错误找不到“MailFolders”

时间:2016-02-02 12:31:49

标签: asp.net office365 office365api

我正在Asp.net webform中创建功能,以在我的某个页面中显示Office 365邮件。 目前我正在使用Microsoft.Office365.Discovery(v1.0.22)和Microsoft.Office365.OutlookServices(v1.0.41.0)nuget包。 我需要显示文件夹明智的总邮件数和总未读数,但Microsoft.Office365.OutlookServices(v.1.0.41.0)确实没有这样的功能。

所以我下载了nugetpackage Microsoft.Office365.OutlookServices(v.2.0.1.0),其中包含属性UnreadItemCount和TotalItemCount

例如:

var folderResult = await outlookServicesClient.Me.MailFolders.ExecuteAsync();
var cnt = folderResult.CurrentPage.ToList()[0].TotalItemCount;

但是当我调用ExecuteAsync()时,它会给出以下错误:

{
   "error":
          {
              "code":"RequestBroker-ParseUri",
              "message":"Resource not found for the segment 'MailFolders'."
          }
}

它有什么问题吗?

Added How to use OutlookServicesClient

DiscoveryClient discClient = new DiscoveryClient(SettingsHelper.DiscoveryServiceEndpointUri,
            async () =>
            {
                var authResult = await authContext.AcquireTokenSilentAsync(SettingsHelper.DiscoveryServiceResourceId, new ClientCredential(SettingsHelper.ClientId, SettingsHelper.AppKey), new UserIdentifier(userObjectId, UserIdentifierType.UniqueId));

                return authResult.AccessToken;
            });

            var dcr = await discClient.DiscoverCapabilityAsync(capabilityName);

            return new OutlookServicesClient(dcr.ServiceEndpointUri,
            async () =>
            {
                var authResult = await authContext.AcquireTokenSilentAsync(dcr.ServiceResourceId, new ClientCredential(SettingsHelper.ClientId, SettingsHelper.AppKey), new UserIdentifier(userObjectId, UserIdentifierType.UniqueId));

                return authResult.AccessToken;
            });

和使用的网址

    private static string _discoverySvcResourceId = "https://api.office.com/discovery/";
    private static string _discoverySvcEndpointUri = "https://api.office.com/discovery/v2.0/me/";

1 个答案:

答案 0 :(得分:2)

如果您使用的是v1 API端点,则会出现该错误。确保在创建OutlookServicesClient对象时以这种方式构建它:

OutlookServicesClient client = 
  new OutlookServicesClient(new Uri("https://outlook.office.com/api/v2.0"), GetToken);