Office 365 error Resource not found for the segment 'MailFolders'

笑着哭i 提交于 2019-12-14 02:46:04

问题


I am creating functionality in Asp.net webform to display Office 365 mails in one of my page. Currently I am using Microsoft.Office365.Discovery (v1.0.22) and Microsoft.Office365.OutlookServices (v1.0.41.0) nuget package. I need to display Folder wise total mail coundand total unread count but Microsoft.Office365.OutlookServices (v.1.0.41.0) does'n have such functionality.

So i downloaded nugetpackage Microsoft.Office365.OutlookServices (v.2.0.1.0) which has properties UnreadItemCount and TotalItemCount

ex:

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

but when i call ExecuteAsync() it gives below error:

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

Is there anything wrong with it?

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;
            });

and URLs that is used

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

回答1:


You'll get that error if you are using the v1 API endpoint. Make sure when you create your OutlookServicesClient object you construct it this way:

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


来源:https://stackoverflow.com/questions/35153626/office-365-error-resource-not-found-for-the-segment-mailfolders

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!