Office365 尝试使用OutlookServicesClient clas获取消息时出现错误404

Office365 尝试使用OutlookServicesClient clas获取消息时出现错误404,office365,exchangewebservices,Office365,Exchangewebservices,以下代码段失败,出现了关于状态代码404的响应的异常: var client = new Microsoft.Office365.OutlookServices .OutlookServicesClient(GetAPIEndpointUri(), GetOrPrepareApplicationAccessTokenAsync ); var messa

以下代码段失败,出现了关于状态代码404的响应的异常:

            var client = new Microsoft.Office365.OutlookServices
                .OutlookServicesClient(GetAPIEndpointUri(), 
                GetOrPrepareApplicationAccessTokenAsync
                );
            var messageFetcher = client.Users[mailbox].Messages.GetById(itemId);
            var message = await messageFetcher.ExecuteAsync();
            message.Subject = subject;
            await message.UpdateAsync();
实际上,以下行失败了:

            var message = await messageFetcher.ExecuteAsync();
查看了异常详细信息中的查询URI,看起来是这样的:

'邮箱%40domain.onmicrosoft.com'/Messages'长消息id'

如何获取访问令牌:

        var authContext = new AuthenticationContext(
            GetAuthorityUrl()
            .ToString()
        );

        var result = await authContext.AcquireTokenAsync(
                GetResourceUrl(),
                new ClientAssertionCertificate(GetClientId(), AppCertificateHelper.GetCertificate())
            );
转换到客户端时的错误信息:

 {"message":"An error has occurred.","exceptionMessage":"An error occurred while processing this request.","exceptionType":"Microsoft.OData.Client.DataServiceQueryException","stackTrace":"   at Microsoft.OData.Client.QueryResult.EndExecuteQuery[TElement](Object source, String method, IAsyncResult asyncResult)\r\n   at Microsoft.OData.Client.DataServiceRequest.EndExecute[TElement](Object source, DataServiceContext context, String method, IAsyncResult asyncResult)\r\n   at Microsoft.OData.Client.DataServiceQuery`1.EndExecute(IAsyncResult asyncResult)\r\n   at Microsoft.Office365.OutlookServices.Extensions.DataServiceContextWrapper.<>c__DisplayClass12`2.<ExecuteSingleAsync>b__10(IAsyncResult i)\r\n   at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at Microsoft.Office365.OutlookServices.Extensions.DataServiceContextWrapper.<ExecuteSingleAsync>d__14`2.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at Microsoft.Office365.OutlookServices.MessageFetcher.<ExecuteAsync>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n   at [[my code]]\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()\r\n   at [[My code]]","innerException":{"message":"An error has occurred.","exceptionMessage":"NotFound","exceptionType":"Microsoft.OData.Client.DataServiceClientException","stackTrace":"   at Microsoft.OData.Client.BaseAsyncResult.EndExecute[T](Object source, String method, IAsyncResult asyncResult)\r\n   at Microsoft.OData.Client.QueryResult.EndExecuteQuery[TElement](Object source, String method, IAsyncResult asyncResult)"}}

答案很简单,就像吃一个苹果。。。 此错误的原因是端点url中的键入错误。 错误URI:

更好的URI:

'邮箱%40domain.onmicrosoft.com'/Messages'长消息id'

差异-指定了API版本

改变终点

替换

1:

而不是用这个


这和你的问题一样吗?不确定。因为我在使用WebAPI HttpClient类发出普通请求时遇到了错误400,但这次使用Office365工具Office365 c client library for outlook。如果是同一问题,为什么会给出不同的状态代码?但是,是的,修复该问题的尝试失败。我不确定是否是相同的错误,这就是我问的原因:。你能发布完整的错误回复吗?我在关于错误的问题中添加了更多细节。虽然我能够解决此错误,但问题仍然存在。
Microsoft.OData.Client.DataServiceQueryException was caught
  HResult=-2146233079
  Message=An error occurred while processing this request.
  Source=Microsoft.OData.Client
  StackTrace:
       at Microsoft.OData.Client.QueryResult.EndExecuteQuery[TElement](Object source, String method, IAsyncResult asyncResult)
       at Microsoft.OData.Client.DataServiceRequest.EndExecute[TElement](Object source, DataServiceContext context, String method, IAsyncResult asyncResult)
       at Microsoft.OData.Client.DataServiceQuery`1.EndExecute(IAsyncResult asyncResult)
       at Microsoft.Office365.OutlookServices.Extensions.DataServiceContextWrapper.<>c__DisplayClass12`2.<ExecuteSingleAsync>b__10(IAsyncResult i)
       at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
       at Microsoft.Office365.OutlookServices.Extensions.DataServiceContextWrapper.<ExecuteSingleAsync>d__14`2.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
       at Microsoft.Office365.OutlookServices.MessageFetcher.<ExecuteAsync>d__0.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
       at [[My code]]
  InnerException: Microsoft.OData.Client.DataServiceClientException
       HResult=-2146233079
       Message=NotFound
       Source=Microsoft.OData.Client
       StatusCode=404
       StackTrace:
            at Microsoft.OData.Client.BaseAsyncResult.EndExecute[T](Object source, String method, IAsyncResult asyncResult)
            at Microsoft.OData.Client.QueryResult.EndExecuteQuery[TElement](Object source, String method, IAsyncResult asyncResult)
       InnerException: 
[0]: {[request-id, e459455e-8bba-42b9-89cb-f6eb94f67b64]}
[1]: {[X-CalculatedBETarget, HK2PR02MB0868.apcprd02.prod.outlook.com]}
[2]: {[X-BackEndHttpStatus, 404]}
[3]: {[X-DiagInfo, HK2PR02MB0868]}
[4]: {[X-BEServer, HK2PR02MB0868]}
[5]: {[X-FEServer, AM3PR07CA0025]}
[6]: {[Content-Length, 0]}
[7]: {[Date, Fri, 06 Feb 2015 18:43:12 GMT]}
[8]: {[Set-Cookie, ClientId=5MTQKAN4QEAXMVUEF5DF0W; expires=Sat, 06-Feb-2016 18:43:06 GMT; path=/; secure; HttpOnly]}
[9]: {[Server, Microsoft-IIS/8.0]}
[10]: {[X-Powered-By, ASP.NET]}
https://outlook.office365.com/api/Users('mailbox%40domain.onmicrosoft.com')/Messages('long message id')
var client = new OutlookServicesClient(new Uri("1url "));