doppelme logo

Example Integration Code

Below are 4 example ASP files that illustrate how to integrate DoppelMe avatars within your website using the SOAP API. These are given for example only and no warranty is provided. These example are given in ASP - but the same prinicples can be applied to code in other languages/frameworks.

doppelme.asp | profile_avatar.asp | profile_avatar_create.asp | profile_avatar_updated.asp

Constants and Utility Functions

Include these constants and utility functions in any pages which make API calls.
<%
'//-------------------------------------
'//DoppelMe Constants
'//-------------------------------------
DOPPELME_SITE        = "http://api.doppelme.com"
DOPPELME_SERVICE    = "http://services.doppelme.com/partnerservice.asmx"    
DM_PARTNER_ID        = 1                             '//put your partner id here
DM_PARTNER_KEY        = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"  '//put your partner key here

'//-------------------------------------
'//DoppelMe Functions
'//-------------------------------------
Function PartnerServiceCall(sURL, sPARAMS)
    
    sURL = DOPPELME_SERVICE & "/" & sURL
    
    Set oHTTP = Server.CreateObject("Msxml2.ServerXMLHTTP")
    oHTTP.Open "POST", sURL, FALSE
    oHTTP.SetRequestHeader "Content-type", "application/x-www-form-urlencoded"
    oHTTP.Send sPARAMS
    if oHTTP.status = 200 then
        sReturnXML = HTMLDecode(oHTTP.responseText)
                    
        '//strip wrapper from return XML
        sReturnXML = Replace(sReturnXML,"<string xmlns=""http://services.doppelme.com/"">","")
        sReturnXML = Replace(sReturnXML,"</string>","")
    else
        sReturnXML = ""
    end if
    PartnerServiceCall = sReturnXML
End Function


Function HTMLDecode(sText)
    Dim I
    sText = Replace(sText, "&quot;", Chr(34))
    sText = Replace(sText, "&lt;"  , Chr(60))
    sText = Replace(sText, "&gt;"  , Chr(62))
    sText = Replace(sText, "&amp;" , Chr(38))
    sText = Replace(sText, "&nbsp;", Chr(32))
    For I = 1 to 255
        sText = Replace(sText, "&#" & I & ";", Chr(I))
    Next
    HTMLDecode = sText
End Function    

'//a very simple sanitizer function given here purely as an example.
'//you should use your own more robust/complete sanitizer 
Function CleanTaintedInput(sText)
    on error resume next
    sText = Replace(sText,"'","")
    
    if Err.number <> 0 then
        sText = ""
    end if
End Function            
%>