def linkedin(self, profile, network, credentials): oauthRequest = oauth.makeOauthRequestObject('https://%s/v1/people/~/connections' % network.base_url, network.getCredentials(), method='GET', token=oauth.OAuthToken.from_string(credentials.token)) ret = oauth.fetchResponse(oauthRequest, network.base_url).read() friends = utils.fromXML(ret).person return [urlparse.parse_qs(y['site_standard_profile_request']['url'])['key'][0] for y in friends if y['site_standard_profile_request']]
def twitter(self, request, network, response): """ Helper function to handle the callbacks for twitter """ # The first step is to make sure there is an unauthed_token in the session, and that it matches the one # the provider gave us back unauthed_token = request.session.get('%s_unauthed_token' % network.name, None) if not unauthed_token: return response.send(errors=NETWORK_HTTP_ERROR % network.name) request.session['%s_unauthed_token' % network.name] requestToken = oauth.OAuthToken.from_string(unauthed_token) # The below ugly hack is brought to you by piston (removes oauth_ keys from request.GET )and urlparse # (places querystring values in lists??) if requestToken.key != urlparse.parse_qs(request.META['QUERY_STRING']).get('oauth_token', [None, ])[0]: return response.send(errors=NETWORK_HTTP_ERROR % network.name) verifier = urlparse.parse_qs(request.META['QUERY_STRING']).get('oauth_verifier', [None, ])[0] #Now we are building a request, so we can exchange this unauthed token for an access_token oauthRequest = oauth.makeOauthRequestObject(network.getAccessTokenURL(), network.getCredentials(), token=requestToken, verifier=verifier) accessToken = oauth.fetchResponse(oauthRequest, network.base_url).read() try: oauth.OAuthToken.from_string(accessToken) except KeyError: return response.send(errors=NETWORK_HTTP_ERROR % network.name) #store the token in the session and in the db, in the future we will look in the session first, and then #the db if that fails request.session['%s_access_token' % network.name] = accessToken params = urlparse.parse_qs(accessToken) if network.name == 'linkedin': oauthRequest = oauth.makeOauthRequestObject('https://%s/v1/people/~' % network.base_url, network.getCredentials(), token=oauth.OAuthToken.from_string(accessToken), method='GET') ret = oauth.fetchResponse(oauthRequest, network.base_url).read() ret = utils.fromXML(ret) params['user_id'] = [urlparse.parse_qs(ret['site_standard_profile_request']['url'])['key'][0], '0'] params['screen_name'] = ['%s %s' % (ret['first_name'], ret['last_name']), '0'] network_dict = {} network_dict['access_token'] = accessToken network_dict['uuid'] = params['user_id'] network_dict['name_in_network'] = params['screen_name'][0] network_dict['network'] = network self.finish_callback(request, response, network_dict=network_dict)