Proporcionar información de autenticación a través de msxml2.ServerXMLHTTP
Estoy usando ASP clásico y tratando de usar la API de JustGiving.
Me gustaría usarlo para mostrar la cantidad total recaudada y el total de donaciones recibidas en mi página de donaciones, en mi sitio web.
Puedo ver que la información está disponible a través de: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
%>
Sin embargo, la página se agota cuando accedo a ella.
Creo que es porque necesito proporcionar alguna información de autenticación como se detalla aquí:https://api.justgiving.com/docs/usage#protectedResources
Así que tengo esa información de autenticación.
Pero no tengo idea de cómo "enviarlo" a la API, para que pueda autenticarme como usuario y proporcionar la información.
También menciona proporcionar información en el encabezado a través del enlace anterior (no puedo publicar el enlace porque no tengo suficiente reputación), pero reemplaza #protectedResources al final de la URL con #contentTypes.
Lo siento, ¿también me estoy perdiendo algo de ese lado?
Lo siento si estoy haciendo preguntas tontas, pero la información en los documentos de la API asume un cierto nivel de inteligencia por parte del usuario, ¡y no tengo mucha información!
Cualquier consejo muy apreciado.
Gracias
Gracias a John por su respuesta.
En base a eso, cambié el código a:
<%
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
%>
Pero lamentablemente la página aún se agota.
Estoy comprobando también a través de: groups.google.com/forum/#!topic/justgiving-api/Xhz5Fkxuy1s
Pero no hay respuesta hasta ahora.
Gracias de nuevo
Versión fija<%
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
%>
Anteriormente estaba usando:
vurl = "https://api.justgiving.com/AP_KEY/v1/account"
Pero cuando lo cambié a https funcionó.
Pensé que lo había intentado anteriormente, pero obviamente no.
Gracias de nuevo a John, realmente aprecio tu ayuda!