简体   繁体   English

使用 Auth 和 2 个标头发出 VBA API 请求?

[英]Making a VBA API Request with Auth and 2 Headers?

I have the following code in Python and want to move the request over to VBA.我在 Python 中有以下代码,并希望将请求移至 VBA。 How do I write this in VBA?我如何在 VBA 中写这个?

import requests
import json

url = "https://us.market-api.kaiko.io/v1/data/order_book_snapshots.v1/exchanges/drbt/option/btc26jun2010000c/snapshots/full?" \
      "start_time=2020-05-29T17:33:00.000000Z&end_time=2020-05-29T17:33:10.000000000Z"

payload = {}
headers = {
  'Accept': 'application/json',
  'x-api-key': '123456'
}

response = requests.request("GET", url, headers=headers, data = payload)
result = json.loads(response.text)
Public Sub testAPI()
Dim http As Object
Dim JSON As Object


Dim pm As Worksheet
Set pm = Sheets("Params")

Set http = CreateObject("MSXML2.XMLHTTP")

http.Open "GET", ("https://us.market-api.kaiko.io/v1/data/order_book_snapshots.v1/exchanges/drbt/option/btc26jun209000p/snapshots/full?start_time=2020-05-29T17:33:00.000Z&end_time=2020-05-29T17:33:30.0Z"), False
http.SetRequestHeader "Accept", "application/json"
http.SetRequestHeader "x-api-key", "1234"

http.Send
Set JSON = ParseJson(http.ResponseText)

pm.Cells(2, 8).Value = JSON("data")(1)("asks")(1)("price")


End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM