问题描述
您好,
我正在尝试从我的网络表单访问我们的办公室365联系人和邮件:
I am trying to access our office 365 contact and mail from my web form:
---- -------------------------------------------------- -------------------------------------------------- -------------------------
---------------------------------------------------------------------------------------------------------------------------------
受保护的异步子Page_Load(ByVal sender As Object,ByVal e As System.EventArgs)Handle Me.Load
使用client = New HttpClient()
Dim endpointUri As String,resourceId As String
使用discoveryRequest =新HttpRequestMessage(列举HTTPMethod [获取]," HTTPS://api.office.com/discovery/v1.0/me/services")
   &NBSP ;            discoveryRequest.Headers.Add(" Authorization"," Bearer {token:http://drezaei.onmicrosoft.com}")
             使用discoveryResponse =等待client.SendAsync(discoveryRequest)
                    暗淡discoverContent =等待discoveryResponse.Content.ReadAsStringAsync()
               &NBSP ;   暗淡serviceInfo = JObject.Parse(discoverContent)
                &NBSP ;   endpointUri = serviceInfo(QUOT; serviceEndpointUri")的ToString()
              &NBSP ;     RESOURCEID = serviceInfo(QUOT; serviceResourceId")的ToString()
              &NBSP ;结束使用
结束使用
使用请求=新HttpRequestMessage(列举HTTPMethod [获取],endpointUri&安培; Convert.ToString(QUOT; / ME /文件夹( '收件箱')/信息$的OrderBy = DateTimeReceived%20desc"?))
                request.Headers.Add(" Authorization",(Convert.ToString(" Bearer {token:")& resourceId)+"}")
使用响应=等待client.SendAsync(请求)
                    暗淡的含量=等待response.Content.ReadAsStringAsync()
               &NBSP ;   对于每个项目在JObject.Parse(内容)中("值")
           Console.WriteLine(" Message"" {0}"""""" {1}""" """""""""&n; DateTimeReceived"))
                   下一页
结束使用
结束使用
结束使用
结束子
Protected Async Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Using client = New HttpClient()
Dim endpointUri As String, resourceId As String
Using discoveryRequest = New HttpRequestMessage(HttpMethod.[Get], "https://api.office.com/discovery/v1.0/me/services")
discoveryRequest.Headers.Add("Authorization", "Bearer {token:http://drezaei.onmicrosoft.com}")
Using discoveryResponse = Await client.SendAsync(discoveryRequest)
Dim discoverContent = Await discoveryResponse.Content.ReadAsStringAsync()
Dim serviceInfo = JObject.Parse(discoverContent)
endpointUri = serviceInfo("serviceEndpointUri").ToString()
resourceId = serviceInfo("serviceResourceId").ToString()
End Using
End Using
Using request = New HttpRequestMessage(HttpMethod.[Get], endpointUri & Convert.ToString("/Me/Folders('Inbox')/Messages?$orderby=DateTimeReceived%20desc"))
request.Headers.Add("Authorization", (Convert.ToString("Bearer {token:") & resourceId) + "}")
Using response = Await client.SendAsync(request)
Dim content = Await response.Content.ReadAsStringAsync()
For Each item In JObject.Parse(content)("value")
Console.WriteLine("Message ""{0}"" received at ""{1}""", item("Subject"), item("DateTimeReceived"))
Next
End Using
End Using
End Using
End Sub
------------------------------------- -----------------
------------------------------------------------------
但每次运行时我都会收到以下错误:
But every time when I run this I get the following error:
endpointUri = serviceInfo(" serviceEndpointUri")。ToString() - > NullReference异常由用户代码处理
endpointUri = serviceInfo("serviceEndpointUri").ToString() -> NullReference exception was handled by user code
我输入的授权或令牌是错误的吗? 我从Azure管理站点获得了令牌。
am I typing my Authorization or token wrong? I got the token from Azure manage site.
我是否需要从其他地方获取令牌或终点uri?
Do i need to get the token or end point uri from somewhere else?
感谢您的任何建议。
Dean
推荐答案
谢谢联系我们。
我目前正在努力收集有关您的请求的更多信息。
我会尽快给你回复。
问候
这篇关于办公室365的API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!