def gather_keys():
    # setup
    pp = pprint.PrettyPrinter(indent=4)
    print('** OAuth Python Library Example **\n')
    client = FitbitOauthClient(CLIENT_KEY, CLIENT_SECRET)

    # get request token
    print('* Obtain a request token ...\n')
    token = client.fetch_request_token()
    print('RESPONSE')
    pp.pprint(token)
    print('')

    print('* Authorize the request token in your browser\n')
    stderr = os.dup(2)
    os.close(2)
    os.open(os.devnull, os.O_RDWR)
    webbrowser.open(client.authorize_token_url())
    os.dup2(stderr, 2)
    try:
        verifier = raw_input('Verifier: ')
    except NameError:
        # Python 3.x
        verifier = input('Verifier: ')

    # get access token
    print('\n* Obtain an access token ...\n')
    token = client.fetch_access_token(verifier)
    print('RESPONSE')
    pp.pprint(token)
    print('')
Beispiel #2
0
def hello_world():
    app.logger.debug("Init FitbitOauthClient")
    client = FitbitOauthClient(CLIENT_KEY, CLIENT_SECRET)

    app.logger.debug("Get request token")
    token = client.fetch_request_token()
    app.logger.debug('RESPONSE')
    app.logger.debug(token)

    # Save the oauth token for use in callback()
    try:
        session['oauth_token'] = token
    except:
        print "Unexpected error:", sys.exc_info()
        raise

    app.logger.debug('* Authorize the request token in your browser\n')
    return render_template('auth.html', link=client.authorize_token_url())
Beispiel #3
0
def callback():
    client = FitbitOauthClient(CLIENT_KEY, CLIENT_SECRET)
    oauth_verifier = request.args.get('oauth_verifier')
    oauth_token = session['oauth_token']
    token = client.fetch_access_token(oauth_verifier, token=oauth_token)
    conn = sqlite3.connect(DATABASE)
    c = conn.cursor()
    # Check if the user exists
    c.execute("SELECT * FROM users  WHERE encoded_user_id = '%s'" %
              token['encoded_user_id'])
    if c.fetchone() != None:
        # Delete the old record
        c.execute("DELETE FROM users WHERE  encoded_user_id = '%s'" %
                  token['encoded_user_id'])
    c.execute("INSERT INTO users VALUES ('%s', '%s', '%s')" %
              (token['encoded_user_id'], token['oauth_token'],
               token['oauth_token_secret']))
    conn.commit()
    conn.close()
    return render_template('callback.html')
Beispiel #4
0
def gather_keys():
    # setup
    client = FitbitOauthClient(CLIENT_KEY, CLIENT_SECRET)

    # get request token
    token = client.fetch_request_token()

    stderr = os.dup(2)
    os.close(2)
    os.open(os.devnull, os.O_RDWR)
    webbrowser.open(client.authorize_token_url())
    os.dup2(stderr, 2)
    try:
        verifier = raw_input('Verifier: ')
    except NameError:
        # Python 3.x
        verifier = input('Verifier: ')

    # get access token
    token = client.fetch_access_token(verifier)
    return token