簡體   English   中英

使用 Auth 和 2 個標頭發出 VBA API 請求?

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

我在 Python 中有以下代碼,並希望將請求移至 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