def get_contacts(self): """ Implements a generator for iterating in contacts """ wll = WindowsLiveLogin(appid=self.consumer_key, secret=self.consumer_secret, policyurl=self.policy_url) consent_token = wll.processConsent(self.post_params) if not consent_token or not consent_token.isValid(): raise Exception('Cannot give a contact list.') 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) return self.parse_contacts(response.read())
def get_auth_url(self): wll = WindowsLiveLogin(appid=self.consumer_key, secret=self.consumer_secret, policyurl=self.policy_url, returnurl=self.callback_url) return wll.getConsentUrl("Contacts.View")