我正在使用经典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,以便它可以对我进行身份验证并提供信息。

它还提到通过该链接上方的链接在 header 上提供信息(由于信誉不佳,因此无法发布该链接),但请在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时,它可以工作。

我以为我以前曾经尝试过,但是显然没有。

再次感谢约翰,非常感谢您的帮助!

请您参考如下方法:

尝试

http.Open "GET", vurl, False, "yourusername", "yourpassword" 

我不知道这是否适用于正义,但它与Bing API兼容

另外,这个问题可能是相关的
XmlHttp Request Basic Authentication Issue

编辑-使用Response.ContentType和Msxml2.ServerXMLHTTP.6.0
vurl = "https://api.justgiving.com/API_KEY/v1/account" 
Set http = Server.CreateObject("msxml2.ServerXMLHTTP.6.0") 
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 
 
Response.ContentType = "application/xml"     
 
Set items = http.responseXML.getElementsByTagName("account") 

等等


评论关闭
IT干货网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!