我尝试连接到VB.NET中的Shopify API并下载一些json订单信息,但每次尝试我都会获得#34; 401未经授权的访问权限#34;错误。我用来实现此目的的代码如下:
'Develop API string to get orders
Dim url As String
url = "https://" & apikey & ":" & apipassword & "@" & domain & "/admin/orders.json"
'Create new web service connection
Dim ws As New WebClient()
'Get json data from remote Shopify server
Dim json_data As String
Try
json_data = ws.DownloadString(url)
Catch ex As Exception
MsgBox("Connection to the remote server failed! Please check your internet connection or contact the developer.", vbOKOnly, "Connection Failed")
Exit Sub
End Try
我了解Shopify使用的另一级授权(OAuth),但我不知道如何实现这一点。如果有人能够提供帮助,我们将不胜感激。
答案 0 :(得分:1)
尝试:
Dim request As WebRequest = WebRequest.Create("https://shop.myshopify.com/admin/orders.json")
request.Credentials = New NetworkCredential("apikey", "password")
Dim response As HttpWebResponse = DirectCast(request.GetResponse(), HttpWebResponse)