Exemple #1
0
def callback():
	"""
	Foursquare calls this URL with our OAuth token. Get the token, get the userId, save them both in our database.
	"""
	verifier = request.args['code']
	clientId = os.getenv('clientId')
	clientSecret = os.getenv('clientSecret')
	callback = os.getenv('callback')
	# use callback code for oauth
	oauth = OAuthHandler(clientId, clientSecret, callback)
	# get the access token and store
	try:
		oauth.get_access_token(verifier)
	except FoursquareError:
		print 'Error, failed to get access token'
	oToken = oauth.access_token
	url='https://api.foursquare.com/v2/users/self?oauth_token='+str(oToken)
	# convert user information json to python dictionary
	userInfo = json.loads(ajaxRequest(url=url))
	userId= userInfo['response']['user']['id'] 
 	# create user model for db
	user= User(userId, oToken)
	# add user model
	db.session.add(user)
	# commit db model
	db.session.commit()	
	return render_template('callback.html')
Exemple #2
0
def auth(request):
    client_id, client_secret, callback = get_consumer_credentials()

    # start the OAuth process, set up a handler with our details
    oauth = OAuthHandler(client_id, client_secret, callback)
    # direct the user to the authentication url
    auth_url = oauth.get_authorization_url()
    response = HttpResponseRedirect(auth_url)

    return response
Exemple #3
0
def callback(request):
    verifier = request.GET.get('code')
    client_id, client_secret, callback = get_consumer_credentials()
    oauth = OAuthHandler(client_id, client_secret, callback)

    # get the access token and store
    try:
        oauth.get_access_token(verifier)
    except FoursquareError:
        print 'Error, failed to get access token'
    request.session['oauth_token'] = oauth.access_token
    response = HttpResponseRedirect(reverse('info'))
    return response