Giter VIP home page Giter VIP logo

fitbit-api-example-python's Introduction

#Fitbit OAuth Flask Template

This project defines a basic structure to make applications based on the Fitbit API. It is written in Python 3.5

It defines an app structure that will give you a database, a login form, and a very basic registration form.

The Flask Structure is from Miguel Grinberg's Book

Repo For His Book Here

If you wish to learn more about Flask check it out. Or the Flask Project Page

Read More About the Fitbit API

Developing Your Own App

First fork this repo

Then create a Fitbit App Config.

This is the config I used while developing. Your app may not need read/write access.

This is the config I used

Once you have that you need to define some environment variables

Here are mine (with secrets faked. Your app will have its own values for most of these). Almost all should be treated with care because if they are leaked your app will be compromised

# Retrieved from dev.fitbit.com/apps/ for the app created earlier
FITBIT_CLIENT_ID=217sdd2
FITBIT_CLIENT_SECRET=321cb9d7g7f8b3c0bf1e24c50169f11
# Key used for CSRF protection
SECRET_KEY=sdasdas
# Signal to the app to use the development config defined in config.py
# When running tests this should be set to 'testing'
FLASK_CONFIG=development

To define an environment variable in Unix environments you can use the export command

export SECRET_KEY=sdasdas

See This superuser post for defining environment variables in windows

After defining those you are ready to setup development.

While the app uses sqlite for development its is designed to eventually be deployed to Heroku and requires Postgres to be installed. You should be able to install this with your package manager of choice. If you don't care about Heroku and dont intend to use Postgres for your production app you can remove the dependency psycopg2 from requirements.txt

# Create a virtual environment for 
pyvenv venv
source venv/bin/activate
pip install -r requirements.txt
# Try the tests! They should pass!
py.test tests

Next, you should decide on the OAuth scopes for your project. Specifically, define what data your app will be accessing from people's Fitbit accounts. These are defined in fitbit.py. This example only uses the profile scope. Your app will almost certainly need more than that.

Read more about OAuth Scopes

Almost there. The first time you run the app you need to create the database. With your virtual environment activated run

python manage.py createdb

Finally to run the app simply make sure your virtual environment is active and run

python manage.py
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
 * Restarting with stat
 * Debugger is active!
 * Debugger pin code: 129-285-482

This app has been put on heroku so you should be able to get it working there as well.

The app as written will only access your fitbit profile to demonstrate OAuth working. Try It Out

fitbit-api-example-python's People

Contributors

bachmann1234 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.