def get(self): try: logging.debug('Hit the Authorize Complete Handler') client_id = 'UNHLIF5EYXSKLX50DASZ2PQBGE2HDOIK5GXBWCIRC55NMQ4C' secret = 'VLKDNIT0XSA5FK3XIO05DAWVDVOXTSUHPE4H4WOHNIZV14G3' redirect = 'https://levr-production.appspot.com/foursquare/authorize/complete' try: logging.info(levr.log_dir(self.request)) except: logging.info(self.request) code = self.request.get('code', None) #if no code was passed, then the authorization is happening through the phone. NO_CODE_MESSAGE = 'Code was not passed. Authorization is happening on phone.' assert code, NO_CODE_MESSAGE logging.info(code) #make request for token url = "https://foursquare.com/oauth2/access_token?client_id=" + client_id + "&client_secret=" + secret + "&grant_type=authorization_code&redirect_uri=" + redirect + "&code=" + code result = urlfetch.fetch(url=url) logging.debug(result.content) foursquare_token = json.loads(result.content)['access_token'] logging.info(foursquare_token) # #grab more user details # url = 'https://api.foursquare.com/v2/users/self?v=20120920&oauth_token='+token # result = urlfetch.fetch(url=url) # response_dict = json.loads(result.content) # # logging.debug(levr.log_dict(response_dict)) #let the foursquare parsing code do its thing user = social.Foursquare(foursquare_token=foursquare_token) user, new_details, new_friends = user.first_time_connect( foursquare_token=foursquare_token) # user.connect_with_content(response_dict,True,foursquare_token=token) logging.debug(levr.log_model_props(user)) logging.debug(levr.log_dict(new_details)) logging.debug(levr.log_dict(new_friends)) #send the founders a text levr.text_notify(user.first_name + ' ' + user.last_name + ' from foursquare') #launch the jinja environment jinja_environment = jinja2.Environment( loader=jinja2.FileSystemLoader(os.path.dirname(__file__))) #set up the jinja template and echo out template = jinja_environment.get_template('templates/landing.html') self.response.out.write(template.render()) logging.debug(levr.log_dict(user)) except AssertionError, e: if e.message == NO_CODE_MESSAGE: #this is an expected case. Authorization is happening on the phone self.response.out.write('Please wait...') else: levr.log_error(e) self.response.out.write('Could not connect with Foursquare.')
def get(self): try: logging.debug('Hit the Authorize Complete Handler') client_id = facebook_auth['client_id'] client_secret = facebook_auth['client_secret'] #======================================================================= # Fetch access_token from facebook #======================================================================= #check for error error = self.request.get('error', None) assert error == None, 'User denied request' state = self.request.get('state', None) code = self.request.get('code', None) logging.debug(state) logging.debug(code) redirect_uri = 'http://levr-production.appspot.com/facebook/authorize/complete' url = 'https://graph.facebook.com/oauth/access_token?client_id={client_id}&redirect_uri={redirect_uri}&client_secret={client_secret}&code={code}'.format( client_id=client_id, redirect_uri=redirect_uri, client_secret=client_secret, code=code) # Fetch the access token from facebook result = urlfetch.fetch(url=url) logging.debug(result.content) logging.debug(type(result.content)) logging.debug(levr.log_dir(result.content)) facebook_token = result.content.split('&')[0].split('=')[1] logging.debug(facebook_token) #======================================================================= # Create User and connect them with levr #======================================================================= #wrap the user in the social class - creates new user if user doesnt exist user = social.Facebook(facebook_token=facebook_token) user, new_details, new_friends = user.first_time_connect( facebook_token=facebook_token) logging.debug(levr.log_model_props(user)) logging.debug(levr.log_dict(new_details)) logging.debug(levr.log_dict(new_friends)) try: logging.debug(user.display_name) logging.debug(user.first_name) logging.debug(user.last_name) logging.debug(user.facebook_id) except: levr.log_error() #send the founders a text levr.text_notify(user.first_name + ' ' + user.last_name + ' from facebook') #set up the jinja template and echo out # template = jinja_environment.get_template('templates/deal.html') # self.response.out.write(template.render(template_values)) self.response.out.write('Hooray! you are connected with levr!') logging.debug(levr.log_dict(user)) except: levr.log_error() self.response.out.write('Could not connect with Facebook')
def get(self): try: logging.debug('Hit the Authorize Complete Handler') client_id = facebook_auth['client_id'] client_secret = facebook_auth['client_secret'] #======================================================================= # Fetch access_token from facebook #======================================================================= #check for error error = self.request.get('error',None) assert error == None, 'User denied request' state = self.request.get('state',None) code = self.request.get('code',None) logging.debug(state) logging.debug(code) redirect_uri = 'http://levr-production.appspot.com/facebook/authorize/complete' url = 'https://graph.facebook.com/oauth/access_token?client_id={client_id}&redirect_uri={redirect_uri}&client_secret={client_secret}&code={code}'.format( client_id= client_id, redirect_uri= redirect_uri, client_secret= client_secret, code= code) # Fetch the access token from facebook result = urlfetch.fetch(url=url) logging.debug(result.content) logging.debug(type(result.content)) logging.debug(levr.log_dir(result.content)) facebook_token = result.content.split('&')[0].split('=')[1] logging.debug(facebook_token) #======================================================================= # Create User and connect them with levr #======================================================================= #wrap the user in the social class - creates new user if user doesnt exist user = social.Facebook(facebook_token=facebook_token) user,new_details,new_friends = user.first_time_connect(facebook_token=facebook_token) logging.debug(levr.log_model_props(user)) logging.debug(levr.log_dict(new_details)) logging.debug(levr.log_dict(new_friends)) try: logging.debug(user.display_name) logging.debug(user.first_name) logging.debug(user.last_name) logging.debug(user.facebook_id) except: levr.log_error() #send the founders a text levr.text_notify(user.first_name + ' ' + user.last_name + ' from facebook') #set up the jinja template and echo out # template = jinja_environment.get_template('templates/deal.html') # self.response.out.write(template.render(template_values)) self.response.out.write('Hooray! you are connected with levr!') logging.debug(levr.log_dict(user)) except: levr.log_error() self.response.out.write('Could not connect with Facebook')
def get(self): try: logging.debug('Hit the Authorize Complete Handler') client_id = 'UNHLIF5EYXSKLX50DASZ2PQBGE2HDOIK5GXBWCIRC55NMQ4C' secret = 'VLKDNIT0XSA5FK3XIO05DAWVDVOXTSUHPE4H4WOHNIZV14G3' redirect = 'https://levr-production.appspot.com/foursquare/authorize/complete' try: logging.info(levr.log_dir(self.request)) except: logging.info(self.request) code = self.request.get('code',None) #if no code was passed, then the authorization is happening through the phone. NO_CODE_MESSAGE = 'Code was not passed. Authorization is happening on phone.' assert code, NO_CODE_MESSAGE logging.info(code) #make request for token url = "https://foursquare.com/oauth2/access_token?client_id="+client_id+"&client_secret="+secret+"&grant_type=authorization_code&redirect_uri="+redirect+"&code="+code result = urlfetch.fetch(url=url) logging.debug(result.content) foursquare_token = json.loads(result.content)['access_token'] logging.info(foursquare_token) # #grab more user details # url = 'https://api.foursquare.com/v2/users/self?v=20120920&oauth_token='+token # result = urlfetch.fetch(url=url) # response_dict = json.loads(result.content) # # logging.debug(levr.log_dict(response_dict)) #let the foursquare parsing code do its thing user = social.Foursquare(foursquare_token=foursquare_token) user,new_details,new_friends = user.first_time_connect( foursquare_token = foursquare_token ) # user.connect_with_content(response_dict,True,foursquare_token=token) logging.debug(levr.log_model_props(user)) logging.debug(levr.log_dict(new_details)) logging.debug(levr.log_dict(new_friends)) #send the founders a text levr.text_notify(user.first_name + ' ' + user.last_name + ' from foursquare') #launch the jinja environment jinja_environment = jinja2.Environment(loader=jinja2.FileSystemLoader(os.path.dirname(__file__))) #set up the jinja template and echo out template = jinja_environment.get_template('templates/landing.html') self.response.out.write(template.render()) logging.debug(levr.log_dict(user)) except AssertionError,e: if e.message == NO_CODE_MESSAGE: #this is an expected case. Authorization is happening on the phone self.response.out.write('Please wait...') else: levr.log_error(e) self.response.out.write('Could not connect with Foursquare.')