问题
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