【发布时间】:2013-12-20 22:02:05
【问题描述】:
我正在使用 Classic ASP 并尝试使用 JustGiving API。
我想用它在我的网站上的捐款页面上显示筹集的总金额和收到的捐款总额。
我可以通过以下方式查看该信息: https://api.justgiving.com/docs/resources/v1/Account/Retrieve
<%
vurl = "http://api.justgiving.com/---myIDhere---/v1/account"
Set http = Server.CreateObject("msxml2.ServerXMLHTTP")
http.Open "GET", vurl, False
http.Send
Set dom = Server.CreateObject("msxml2.DOMDocument")
dom.loadXML http.responseText
Set items = dom.getElementsByTagName("account")
For Each item In items
Set var_totalDonated = item.getElementsByTagName("totalDonated")
If NOT (var_totalDonated IS Nothing) Then
var_totalDonated = ap(totalDonated(0).Text)
response.write var_totalDonated
End If
Next
%>
但是,当我访问它时页面超时。
我认为这是因为我需要提供一些身份验证信息,如下所述: https://api.justgiving.com/docs/usage#protectedResources
所以我得到了那个身份验证信息。
但我不知道如何将其“发送”到 API,以便它可以验证我的用户身份并提供信息。
它还提到通过此链接上方的链接提供有关标题的信息(我无法发布链接,因为我没有足够的声誉),但将 URL 末尾的 #protectedResources 替换为 #contentTypes。
对不起 - 我也错过了那方面的东西吗?
如果我问了一些愚蠢的问题,我很抱歉,但 API 文档中的信息假定用户具有一定程度的智能,而我没有很多!
非常感谢任何建议。
谢谢
感谢约翰的回复。
基于此,我将代码改为:
<%
vurl = "https://api.justgiving.com/API_KEY/v1/account"
Set http = Server.CreateObject("msxml2.ServerXMLHTTP")
http.Open "GET", vurl, False, "username", "pwd"
http.setTimeouts 5000, 5000, 10000, 10000 ''ms - resolve, connect, send, receive
http.setRequestHeader "Authorization", "Basic MY_AUTH_STRING"
http.Send
Set dom = Server.CreateObject("msxml2.DOMDocument")
dom.loadXML http.responseText
Set items = dom.getElementsByTagName("account")
For Each item In items
Set var_totalDonated = item.getElementsByTagName("totalDonated")
If NOT (var_totalDonated IS Nothing) Then
var_totalDonated = (var_totalDonated(0).Text)
response.write var_totalDonated
End If
Next
%>
但不幸的是页面仍然超时。
我也在通过以下方式进行检查: groups.google.com/forum/#!topic/justgiving-api/Xhz5Fkxuy1s
但目前还没有答案。
再次感谢
固定版本
<%
Sub debug( varName )
Dim varValue
varValue = Eval( varName )
response.write "<p style='margin:10px; border-bottom:2px solid #ccc;border-top:1px solid #eaeaea;background-color:white;padding:10px;color:red;text-align:left;'><strong>" & varName & "</strong>: " & varvalue & "</p>" & vbcrlf & vbcrlf
End Sub
vurl = "https://api.justgiving.com/AP_KEY/v1/account"
Set http = Server.CreateObject("msxml2.ServerXMLHTTP")
http.Open "GET", vurl, False, username, password
http.setTimeouts 5000, 5000, 10000, 10000 'ms - resolve, connect, send, receive
http.setRequestHeader "Authorization", "Basic AUTH_STRING"
http.Send
Response.ContentType = "application/xml"
Set dom = Server.CreateObject("msxml2.DOMDocument")
dom.loadXML http.responseText
Set items = dom.getElementsByTagName("account")
For Each item In items
Set var_totalDonated = item.getElementsByTagName("totalDonated")
If NOT (var_totalDonated IS Nothing) Then
var_totalDonated = ap(var_totalDonated(0).Text)
debug "var_totalDonated"
End If
Set var_totalRaised = item.getElementsByTagName("totalRaised")
If NOT (var_totalRaised IS Nothing) Then
var_totalRaised = ap(var_totalRaised(0).Text)
debug "var_totalRaised"
End If
Set var_totalGiftAid = item.getElementsByTagName("totalGiftAid")
If NOT (var_totalGiftAid IS Nothing) Then
var_totalGiftAid = ap(var_totalGiftAid(0).Text)
debug "var_totalGiftAid"
End If
Next
%>
以前我用的是:
vurl = "https://api.justgiving.com/AP_KEY/v1/account"
但是当我将其更改为 https 时,它起作用了。
我以为我以前尝试过,但显然没有。
再次感谢约翰,非常感谢您的帮助!
【问题讨论】:
标签: api asp-classic