Providing authentication info via msxml2.ServerXMLHTTP

前端 未结 2 1003
南笙
南笙 2020-12-03 23:11

I am using Classic ASP and trying to use the JustGiving API.

I\'d like to use it to display the total amount raised, and total donations received on my donation page

相关标签:
2条回答
  • 2020-12-03 23:43

    Apologies for adding to an old post. However this has consistently come up when Googling for help on MailChimp API V3.0 and VBA.

    This is the fix I used:

    ret = objhttp.Open("POST", sURL, False) 
    objhttp.setRequestHeader "Content-Type", "application/json"
    objhttp.setRequestHeader "Accept", "application/json"
    
    'V3 API uses HTTP Basic Authorisation inside an https: wrapper.
    'The standard windows method does not seem to work however the 
    'following hack does.
    'In summary the user name and APIkey are seperated with a Colon: and 
    'base 64 encoded and added to a Http RequestHeader
    
    
    objhttp.setRequestHeader "Authorization", "Basic " & Base64Encode(APIUser & ":" & ApiKey)
    
    objhttp.send (sJson)
    

    You will need to code the Base64Encode function. I grabbed some code from http://pastie.org/1192157 (Ex StackOverflow) and pasted it into a VBA Module.

    Hope it helps.

    0 讨论(0)
  • 2020-12-03 23:46

    Try

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

    I don't know if this works on justgiving, but it does with the Bing API

    Also, this question may be relevant XmlHttp Request Basic Authentication Issue

    Edit - using Response.ContentType and 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")
    

    etc

    0 讨论(0)
提交回复
热议问题