找不到段 'MailFolders' 的 Office 365 错误资源
Office 365 error Resource not found for the segment 'MailFolders'
我正在 Asp.net 网络表单中创建功能以在我的一个页面中显示 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;
});
和使用的 URL
private static string _discoverySvcResourceId = "https://api.office.com/discovery/";
private static string _discoverySvcEndpointUri = "https://api.office.com/discovery/v2.0/me/";
如果您使用 v1 API 端点,您将收到该错误。确保在创建 OutlookServicesClient
对象时以这种方式构造它:
OutlookServicesClient client =
new OutlookServicesClient(new Uri("https://outlook.office.com/api/v2.0"), GetToken);
我正在 Asp.net 网络表单中创建功能以在我的一个页面中显示 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;
});
和使用的 URL
private static string _discoverySvcResourceId = "https://api.office.com/discovery/";
private static string _discoverySvcEndpointUri = "https://api.office.com/discovery/v2.0/me/";
如果您使用 v1 API 端点,您将收到该错误。确保在创建 OutlookServicesClient
对象时以这种方式构造它:
OutlookServicesClient client =
new OutlookServicesClient(new Uri("https://outlook.office.com/api/v2.0"), GetToken);