If anyone is struggling with importing contacts from Hotmail like I
was - here's the code that works.

@login_required
def hotmail_login(request):
    from lib.WindowsLiveLogin import WindowsLiveLogin
    wll = WindowsLiveLogin(appid=settings.WINDOWS_APPID,
secret=settings.WINDOWS_SECRET,
                           policyurl='<put your policy url here, it
won't work without it!>')
    url = wll.getConsentUrl("Contacts.View")
    return redirect(url)

@login_required
def hotmail_callback(request):
    from lib.WindowsLiveLogin import WindowsLiveLogin
    import urllib, urllib2
    wll = WindowsLiveLogin(appid=settings.WINDOWS_APPID,
secret=settings.WINDOWS_SECRET, policyurl='<policy url again>')

    class Obj(object):
        pass

    fs = {}
    for var in request.POST:
        fs[var] = Obj()
        fs[var].value =  request.POST.get(var)
    consent_token = wll.processConsent(fs)
    if consent_token and consent_token.isValid():
        lid = consent_token.getLocationID()
        lid16 = int(lid, 16)
        to_signed_64 = lambda x: x < 2**63 and x or x - 2**64
        lid_s64 = to_signed_64(lid16)
        url = 'https://livecontacts.services.live.com/users/@c...@%s/rest/
invitationsbyemail' % lid_s64
        req = urllib2.Request(url)
        req.add_header('Authorization', 'DelegatedToken dt="%s"' %
urllib.unquote(consent_token.getDelegationToken()))
        response = urllib2.build_opener().open(req)
        the_page = response.read()
        return HttpResponse(the_page)


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to