def user_info(self, req): try: user = self.service().people().get(userId='me').execute( self.http(req)) auth_id = User.generate_auth_id('google', user['id'], 'plus') urls = user.get('urls') if user.get('url'): urls.append({ u'type': u'google#plus', u'value': user.get('url') }) except Exception: return self.raise_error( 'There was an error contacting Google Plus. ' 'Note this strategy requires a Google Plus Account. ' 'If you have a Google Plus Account ' 'please try again.') return { 'auth_id': auth_id, 'info': { 'id': user['id'], 'displayName': user.get('displayName'), }, 'extra': { 'raw_info': user, } }
def user(self, username): session = self.getSession() user = self.getUser() profiles = [] if user: profiles = self.getUserProfiles(user) owner = User.query(User.username == username).fetch() if not owner: return self.render_template( "404.html", { "title": "Map of Life - Not Found", "user": user, "session": session, "profiles": profiles, "header": "default", }, ) owner = owner[0] owner_profiles = self.getUserProfiles(owner) self.render_template( "user.html", { "title": owner.username + " (" + user.displayName + ")", "user": user, "session": session, "profiles": profiles, "owner": owner, "owner_profiles": owner_profiles, "model": dumps(owner), "header": "user", }, )
def user_info(self, req): url = "https://api.stackexchange.com/2.0/me/associated?pagesize=100&key=%s&access_token=%s" % ( key.api_key, req.credentials.access_token) res, results = self.http(req).request(url) if res.status is not 200: return self.raise_error( 'There was an error contacting StackExchange. ' 'Please try again.') se_user = get_stackexchange_user(json.loads(results)['items']) url = "https://api.stackexchange.com/2.0/me?site=%s&key=%s&access_token=%s" % ( se_user.main_site_key, key.api_key, req.credentials.access_token) res, results = self.http(req).request(url) if res.status is not 200: return self.raise_error( 'There was an error contacting StackExchange. ' 'Please try again.') main_user = json.loads(results)['items'][0] auth_id = User.generate_auth_id(req.provider, main_user['user_id']) return { 'auth_id': auth_id, 'info': { 'id': main_user['user_id'], 'displayName': main_user.get('display_name'), }, 'extra': { 'raw_info': main_user, 'associated_sites': se_user.associated_sites, 'associated_sites_keys': se_user.associated_sites_keys } }
def user_info(self, req): url = "https://www.googleapis.com/oauth2/v1/userinfo?access_token=" +\ req.credentials.access_token res, results = self.http(req).request(url) if res.status is not 200: return self.raise_error('There was an error contacting Google. ' 'Please try again.') user = json.loads(results) auth_id = User.generate_auth_id('google', user['id'], 'userinfo') uinfo = { 'auth_id': auth_id, 'info': { 'id': user['id'], 'displayName': user.get('name'), 'givenName': user.get('given_name'), 'familyName': user.get('family_name'), 'image': { 'url': user.get('picture'), }, 'emails': [ { 'value': user.get('email'), # email 'verified': True # email }, ], }, 'extra': { 'raw_info': user, } } return uinfo
def user_info(self, req): url = "https://api.stackexchange.com/2.0/me/associated?pagesize=100&key=%s&access_token=%s" % (key.api_key, req.credentials.access_token) res, results = self.http(req).request(url) if res.status is not 200: return self.raise_error('There was an error contacting StackExchange. ' 'Please try again.') se_user = get_stackexchange_user(json.loads(results)['items']) url = "https://api.stackexchange.com/2.0/me?site=%s&key=%s&access_token=%s" % (se_user.main_site_key, key.api_key, req.credentials.access_token) res, results = self.http(req).request(url) if res.status is not 200: return self.raise_error('There was an error contacting StackExchange. ' 'Please try again.') main_user = json.loads(results)['items'][0] auth_id = User.generate_auth_id(req.provider, main_user['user_id']) return { 'auth_id': auth_id, 'info': { 'id': main_user['user_id'], 'displayName': main_user.get('display_name'), }, 'extra': { 'raw_info': main_user, 'associated_sites': se_user.associated_sites, 'associated_sites_keys': se_user.associated_sites_keys } }
def user_info(self, req): url = "http://api.linkedin.com/v1/people/~:({0})?format=json".format( ','.join(self.fields())) res, results = self.http(req).request(url) if res.status is not 200: return self.raise_error('There was an error contacting LinkedIn. Please try again.') user = json.loads(results) logging.info(user) auth_id = User.generate_auth_id(req.provider, user['id']) return { 'auth_id': auth_id, 'info': { 'id': user.get('id'), # Unique ID to the service provider 'displayName': "{0} {1}".format(user.get('firstName'), user.get('lastName')), 'name': { 'formatted': "{0} {1}".format(user.get('firstName'), user.get('lastName')), 'familyName': user.get('lastName'), 'givenName': user.get('firstName'), # 'middleName': user.get('middle_name'), 'honorificPrefix': None, 'honorificSuffix': None, }, 'emails': [ { 'value': user.get('email-address'), # email 'type': None, # home, work 'primary': True, # boolean 'verified': True # email }, ], 'image': { 'url': user.get('pictureUrl') }, 'industry': user.get('industry'), # 'utcOffset': user.get('utc_offset'), # 'locale': user.get('lang'), # 'verified': user.get('verified'), # 'nickname': user.get('screen_name'), # 'location': user.get('location'), # user_location 'aboutMe': user.get('headline'), # 'photos': [ # { # 'value': user.get('profile_image_url'), # 'type': 'full' # }, # { # 'value': user.get('profile_image_url_https'), # 'type': 'https' # }, # ], 'image': { 'url': user.get('pictureUrl'), }, }, 'extra': { 'raw_info': user, }, }
def user_info(self, req): url = "https://graph.facebook.com/me?access_token=" + \ req.credentials.access_token res, results = self.http(req).request(url) if res.status is not 200: return self.raise_error('There was an error contacting Facebook. ' 'Please try again.') user = json.loads(results) auth_id = User.generate_auth_id(req.provider, user['id']) return { 'auth_id': auth_id, 'info': { 'id': user['id'], 'displayName': user.get('name'), 'name': { 'formatted': user.get('name'), 'familyName': user.get('last_name'), 'givenName': user.get('first_name'), # 'middleName': user.get('middle_name'), # 'honorificPrefix': None, # 'honorificSuffix': None, }, 'birthday': user.get('birthday'), # user_birthday 'gender': user.get('gender'), 'utcOffset': user.get('timezone'), 'locale': user.get('locale'), 'verified': user.get('verified'), 'emails': [ { 'value': user.get('email'), # email 'type': None, # home, work 'primary': True, # boolean 'verified': True # email }, ], 'nickname': user.get('login'), 'location': user.get('location'), # user_location 'aboutMe': user.get('bio'), 'image': { 'url': "http://graph.facebook.com/{0}/picture?type=square".format(user.get('id')) }, 'urls': [ { 'type': 'github', 'value': "https://github.com/{0}".format(user.get('link')), }, { 'type': 'blog', 'value': user.get('blog'), }, ], }, 'extra': { 'raw_info': user, } }
def user_info(self, req): url = "https://api.github.com/user?access_token=" +\ req.credentials.access_token res, results = self.http(req).request(url) if res.status is not 200: return self.raise_error('There was an error contacting Github. ' 'Please try again.') user = json.loads(results) auth_id = User.generate_auth_id(req.provider, user['id']) return { 'auth_id': auth_id, 'info': { 'id': user['id'], 'displayName': user.get('name'), 'name': { 'formatted': user.get('name'), # 'familyName': user.get('last_name'), # 'givenName': user.get('first_name'), # 'middleName': user.get('middle_name'), # 'honorificPrefix': None, # 'honorificSuffix': None, }, # 'birthday': user.get('birthday'), # user_birthday # 'gender': user.get('gender'), # 'utcOffset': user.get('timezone'), # 'locale': user.get('locale'), # 'verified': user.get('verified'), 'emails': [ { 'value': user.get('email'), # email 'type': None, # home, work 'primary': True # boolean }, ], 'username': user.get('login'), 'location': user.get('location'), 'aboutMe': user.get('bio'), 'company': user.get('company'), 'image': { 'url': user.get('avatar_url'), }, 'urls': [ { 'type': 'github', 'value': user.get('html_url'), }, { 'type': 'blog', 'value': user.get('blog'), }, ], }, 'extra': { 'raw_info': user, } }
def user_info(self, req): url = "https://api.github.com/user?access_token=" +\ req.credentials.access_token res, results = self.http(req).request(url) if res.status is not 200: return self.raise_error('There was an error contacting Github. ' 'Please try again.') user = json.loads(results) auth_id = User.generate_auth_id(req.provider, user['id']) return { 'auth_id': auth_id, 'info': { 'id': user['id'], 'displayName': user.get('name'), 'name': { 'formatted': user.get('name'), # 'familyName': user.get('last_name'), # 'givenName': user.get('first_name'), # 'middleName': user.get('middle_name'), # 'honorificPrefix': None, # 'honorificSuffix': None, }, # 'birthday': user.get('birthday'), # user_birthday # 'gender': user.get('gender'), # 'utcOffset': user.get('timezone'), # 'locale': user.get('locale'), # 'verified': user.get('verified'), 'emails': [ { 'value': user.get('email'), # email 'type': None, # home, work 'primary': True # boolean }, ], 'nickname': user.get('username'), 'location': user.get('location'), 'aboutMe': user.get('bio'), 'company': user.get('company'), 'image': { 'url': user.get('avatar_url'), }, 'urls': [ { 'type': 'github', 'value': user.get('html_url'), }, { 'type': 'blog', 'value': user.get('blog'), }, ], }, 'extra': { 'raw_info': user, } }
def user_info(self, req): url = 'https://api.twitter.com/1.1/account/verify_credentials.json' res, results = self.http(req).request(url) if res.status is not 200: raise('A {0} error.'.format(req.provider)) user = json.loads(results) try: auth_id = User.generate_auth_id(req.provider, user['id']) except: raise('A {0} error.'.format(req.provider)) return { 'auth_id': auth_id, 'info': { 'id': user.get('id'), # Unique ID to the service provider 'displayName': user.get('name'), 'name': { 'formatted': user.get('name'), # 'familyName': user.get('family_name'), # 'givenName': user.get('given_name'), # 'middleName': user.get('middle_name'), # 'honorificPrefix': None, # 'honorificSuffix': None, }, 'urls': [ { 'type': 'twitter#profile', 'value': user.get('url'), 'primary': True, }, ], 'utcOffset': user.get('utc_offset'), 'locale': user.get('lang'), 'verified': user.get('verified'), 'nickname': user.get('screen_name'), 'location': user.get('location'), # user_location 'aboutMe': user.get('description'), 'photos': [ { 'value': user.get('profile_image_url'), 'type': 'full' }, { 'value': user.get('profile_image_url_https'), 'type': 'https' }, ], 'image': { 'url': user.get('profile_image_url'), }, }, 'extra': { 'raw_info': user, }, }
def user_info(self, req): url = "https://api.foursquare.com/v2/users/self?oauth_token=" + \ req.credentials.access_token res, results = self.http(req).request(url) if res.status is not 200: return self.raise_error('There was an error contacting Foursquare. ' 'Please try again.') try: user = json.loads(results)['response']['user'] except KeyError: return self.raise_error('There was an error contacting Foursquare. ' 'Please try again.') auth_id = User.generate_auth_id(req.provider, user['id']) return { 'auth_id': auth_id, 'info': { 'id': user['id'], 'displayName':("{0} {1}".format(user.get('firstName'), user.get('lastName', '')).strip()), 'name': { 'formatted':("{0} {1}".format(user.get('firstName'), user.get('lastName', '')).strip()), 'familyName': user.get('lastName'), 'givenName': user.get('firstName'), # 'middleName': user.get('middle_name'), # 'honorificPrefix': None, # 'honorificSuffix': None, }, # 'birthday': user.get('birthday'), # user_birthday 'gender': user.get('gender'), # 'utcOffset': user.get('timezone'), # 'locale': user.get('locale'), # 'verified': user.get('verified'), 'emails': [ { 'value': user['contact'].get('email') if 'contact' in user else None, # email 'type': None, # home, work 'primary': True # boolean }, ], 'nickname':("{0} {1}".format(user.get('firstName'), user.get('lastName', '')).strip()), 'location': user.get('homeCity'), # user_location # 'aboutMe': user.get('bio'), 'image': { 'url': user.get('photo') }, # 'urls': [], }, 'extra': { 'raw_info': user, } }
def user_info(self, req): try: user = self.service().people().get(userId='me').execute(self.http(req)) auth_id = User.generate_auth_id('google', user['id'], 'plus') urls = user.get('urls') if user.get('url'): urls.append({u'type':u'google#plus', u'value': user.get('url')}) except Exception: return self.raise_error('There was an error contacting Google Plus. ' 'Note this strategy requires a Google Plus Account. ' 'If you have a Google Plus Account ' 'please try again.') return { 'auth_id': auth_id, 'info': { 'id': user['id'], 'displayName': user.get('displayName'), }, 'extra': { 'raw_info': user, } }
def user_info(self, req): url = "https://api.instagram.com/v1/users/self/?access_token=" + \ req.credentials.access_token res, results = self.http(req).request(url) if res.status is not 200: return self.raise_error('There was an error contacting Instagram. ' 'Please try again.') user = json.loads(results)['data'] auth_id = User.generate_auth_id(req.provider, user['id']) return { 'auth_id': auth_id, 'info': { 'id': user['id'], 'displayName': user.get('username'), 'name': { 'formatted': user.get('full_name'), # 'familyName': user.get('last_name'), # 'givenName': user.get('first_name'), # 'middleName': user.get('middle_name'), # 'honorificPrefix': None, # 'honorificSuffix': None, }, 'nickname': user.get('username'), 'aboutMe': user.get('bio'), 'image': { 'url': user.get('profile_picture') }, 'urls': [ { 'type': 'website', 'value': user.get('website'), }, ], }, 'extra': { 'raw_info': user, } }
def user_info(self, req): url = "https://apis.live.net/v5.0/me?{0}"# + urlencode({'access_token':req.credentials.access_token}) #logging.info("live.1: " + url.format(urlencode({'access_token':req.credentials.access_token}))) #res, results = self.http(req).request(url) results = urlfetch.fetch(url.format(urlencode({'access_token':req.credentials.access_token}))).content #logging.info("live.2") #logging.info("live.3: " + res) #if res.status is not 200: # return self.raise_error('There was an error contacting Windows Live. ' # 'Please try again.') #logging.info("live.4: " + results) user = json.loads(results) auth_id = User.generate_auth_id(req.provider, user['id']) uinfo = { 'auth_id': auth_id, 'info': { 'id': user['id'], 'displayName': user.get('name'), 'name': { 'givenName': user.get('first_name'), 'familyName': user.get('last_name'), }, 'image': { 'url': ""#user.get('picture'), }, 'emails': [ { 'value': user.get('emails').get('preferred'), 'verified': True # email }, ], }, 'extra': { 'raw_info': user, } } return uinfo
def user_info(self, req): # get user id url = 'https://api.weibo.com/2/account/get_uid.json?access_token={}'.format(req.credentials.access_token) res, results = self.http(req).request(url) if res.status != 200: return self.raise_error('There was an error contacting Sina Weibo. Please try again.') uid = json.loads(results)['uid'] # get user data url = 'https://api.weibo.com/2/users/show.json?uid={}&access_token={}'.format(uid, req.credentials.access_token) res, results = self.http(req).request(url) if res.status != 200: return self.raise_error('There was an error contacting Sina Weibo. Please try again.') user = json.loads(results) user_dict = { 'auth_id': User.generate_auth_id(req.provider, user['id']), 'uid': user['id'], 'info': { 'id': user.get('id'), 'displayName': user.get('screen_name'), 'name': { 'formatted': user.get('name') }, 'gender': user.get('gender'), 'urls': [{ 'value': user.get('url') }], 'verified': user.get('verified'), 'location': user.get('location'), 'image': { 'url': user.get('profile_image_url') } }, 'extra': { 'raw_info': user, } } return user_dict
def user_info(self, req): url = "http://api.linkedin.com/v1/people/~:({0})?format=json".format( ','.join(self.fields())) res, results = self.http(req).request(url) if res.status is not 200: return self.raise_error( 'There was an error contacting LinkedIn. Please try again.') user = json.loads(results) auth_id = User.generate_auth_id(req.provider, user['id']) return { 'auth_id': auth_id, 'info': { 'id': user.get('id'), # Unique ID to the service provider 'displayName': "{0} {1}".format(user.get('firstName'), user.get('lastName')), 'name': { 'formatted': "{0} {1}".format(user.get('firstName'), user.get('lastName')), 'familyName': user.get('lastName'), 'givenName': user.get('firstName'), # 'middleName': user.get('middle_name'), 'honorificPrefix': None, 'honorificSuffix': None, }, 'urls': [ { 'type': 'linkedin#profile', 'value': user.get('publicProfileUrl'), 'primary': True, }, ], 'industry': user.get('industry'), # 'utcOffset': user.get('utc_offset'), # 'locale': user.get('lang'), # 'verified': user.get('verified'), # 'nickname': user.get('screen_name'), # 'location': user.get('location'), # user_location 'aboutMe': user.get('headline'), # 'photos': [ # { # 'value': user.get('profile_image_url'), # 'type': 'full' # }, # { # 'value': user.get('profile_image_url_https'), # 'type': 'https' # }, # ], 'image': { 'url': user.get('pictureUrl'), }, }, 'extra': { 'raw_info': user, }, }