来自 Excel VBA 的 RESTful API 调用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41928324/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
RESTful API call from Excel VBA
提问by Scott
I'm attempting to access the online API of http://api.football-data.org/indexusing Excel VBA to eventually populate an excel sheet with a click of a button. Currently I have:
我正在尝试使用 Excel VBA访问http://api.football-data.org/index的在线 API,最终通过单击按钮来填充 Excel 工作表。目前我有:
Sub apiTest()
Dim oRequest As Object
Set oRequest = CreateObject("WinHttp.WinHttpRequest.5.1")
oRequest.Open "GET", "http://api.football-data.org/v1/competitions/354/fixtures/?matchday=22", False
oRequest.SetRequestHeader "X-Auth-Token", "replace this with my api token"
oRequest.Send
MsgBox oRequest.ResponseText
End Sub
According to the site, all I need to do is to add the X-Auth-Token field to the header and it should work. However, when I try to run this the response body says "The resource you are looking for is restricted". Am I using WinHTTPRequest improperly?
根据该站点,我需要做的就是将 X-Auth-Token 字段添加到标题中,它应该可以工作。但是,当我尝试运行它时,响应正文显示“您正在寻找的资源受到限制”。我是否不正确地使用 WinHTTPRequest?
采纳答案by Yohan Chung
I have checked its documentation. The error (403 Restricted Resource) is to do with the followings:
我检查了它的文档。错误 (403 Restricted Resource) 与以下内容有关:
- the resource is only available to authenticated clients
- the resource is only available to donating clients
- the resource is not available in the API version you are using
- 该资源仅对经过身份验证的客户端可用
- 该资源仅适用于捐赠客户
- 该资源在您使用的 API 版本中不可用
Also, X-Response-Control seems to be included as request header (See the doc).
此外,X-Response-Control 似乎包含在请求标头中(请参阅文档)。