def fe_connect(request): """ Do the OAuth dance for Fire Eagle! """ CONSUMER_KEY = FE_CONSUMER_KEY CONSUMER_SECRET = FE_CONSUMER_SECRET CALLBACK_URL = FE_CALLBACK_URL fe = FireEagle( CONSUMER_KEY, CONSUMER_SECRET ) request_token = fe.request_token( oauth_callback=CALLBACK_URL ) if ( Token.gql( "WHERE user = :1", str(request.user) ).get() != None ): token = Token.gql( "WHERE user = :1", str(request.user) ).get() else: token = Token() token.user = str(request.user) token.fe_request_token = str(request_token) token.put() auth_url = fe.authorize( request_token, oauth_callback=CALLBACK_URL ) return redirect( auth_url )
# Die if we've already authorized if path.exists( settings.AUTH_FILE ): print "It looks like you already authorized Fire Eagle. Bye!" exit() def pause( prompt='hit to continue' ): return raw_input( '\n' + prompt + '\n' ) fe = FireEagle( settings.CONSUMER_KEY, settings.CONSUMER_SECRET ) ## Step 1 - Get a request token request_token = fe.request_token() ## Step 2 - Ask the user to authorize the application, using that request token auth_url = fe.authorize( request_token ) print auth_url pause( 'Please authorize the app at that URL' ) ## Step 3 - Convert the request token into an access token access_token = fe.access_token( request_token ) ## (Step 4 - save the access token) token_file = open( settings.AUTH_FILE, 'w' ) try: pickle.dump( access_token, token_file ) finally: token_file.close()
from fireeagle_api import FireEagle fe = FireEagle( "MLxYXHDkLiA8", "r9qanNnpBvFX3mF3xmI98Hsjsg3zJ389" ) # dev application_token = fe.request_token() auth_url = fe.authorize( application_token ) print auth_url pause( 'Please authorize the app at that URL!' ) user_token = fe.access_token( application_token ) print fe.lookup( user_token, q='London, England' ) print fe.user( user_token )