首页 > 解决方案 > Excel 2010 VBA - 尝试使用 API JSON 从站点检索数据

问题描述

预先感谢您的任何帮助!!第一次使用 api 调用。尝试从我位于 artofbooks.com 的库存文件中检索信息的单元格中输入 ISBN 他们的 API 调用文档不是很好。这是我的代码,我收到“错误令牌”错误。

 sub test
    creds = EncodeBase64("{ AOB_AUTH_USER : cottagebooks, AOB_AUTH_PW : xxxxxx }")
    isbn = Cells(5, 3).Value
   
    
    Set objHttp = CreateObject("MSXML2.ServerXMLHTTP.6.0")
    URL = "https://www.theartofbooks.com/api/2.0/item=2010101257"
    objHttp.Open "GET", URL, False
    objHttp.SetRequestHeader "Content-Type", "multipart/form-data"
    objHttp.SetRequestHeader "Accept", "application/xml"
    objHttp.SetRequestHeader "Authorization:", "Bearer " & creds
    
    objHttp.Send
    strResponseStatus = objHttp.Status
    strresponsetext = objHttp.ResponseText
    strresponsetext = CStr(strresponsetext)
         
   MsgBox strresponsetext
end sub

标签: jsonexcelvbaapi

解决方案


推荐阅读