Git Product home page Git Product logo

pkpio / fitbit-googlefit Goto Github PK

View Code? Open in Web Editor NEW
484.0 24.0 61.0 321 KB

Export Fitbit data to Google Fit. Unlike the alternatives such as fitnessyncer.com, this offers very fine intraday granularity (every minute/second data).

Home Page: http://pkp.io/blog/fitbit-to-googlefit-sync/

License: GNU General Public License v3.0

Python 98.72% Shell 0.17% Dockerfile 1.10%
fitbit fitbit-data sync fitbit-steps google-fit

fitbit-googlefit's Introduction

Introduction


Export all your Fitbit data to Google Fit. If you find this useful, please star ⭐ the repository on Github.

Unlike other alternatives, such as fitnessyncer.com, this aims to offer very fine granularity for the data.

Fitbit Steps GoogleFit Steps demo

Features


  • Steps - minute level precision
  • Distance - minute level precision
  • Heart rate - second level precision
  • Weight
  • Body fat percentage
  • Activities
    • Running
    • Swimming
    • Biking
    • Volleyball
    • Walking
    • Badminton
    • Workouts
    • Fencing
    • Cricket
    • Football
    • Hiking
    • And a [few others][activities] -- suggestions welcome!
  • Calories - minute level precision
  • Sleep logs - minute level precision

Adding new activities

To add new activities

Setup


You have to register your own Fitbit and Google Fit applications. This setup is a one time thing.

  1. Install dependencies

This is a python3 application so install all the dependencies

  • Create virtualenv virtualenv fitbitenv
  • Activate env source fitbitenv/bin/activate
  • Install dependencies using pip3 install -r requirements.txt
  1. Fitbit setup

All instructions below must be performed using the same Fitbit account you want to sync with Google Fit.

Application Name : --
Description : --
Application Website : --
Organization : --
Organization Website : --
OAuth 2.0 Application Type : **Personal**
Callback URL : http://localhost:8080/
Default Access Type : Read-Only

Note : 
1. Use your own information for fields marked --
2. Make sure you copy the Callback URL exactly (including the last /)
3. Application Type MUST be Personal
  • Hit save and make a note of OAuth 2.0 Client ID and Client Secret
  • Navigate to auth folder cd /auth
  • run python3 auth_fitbit.py -i <client-id> -s <client-secret>
  • This opens a popup in the browser. Authenticate and done!
  1. Google Fit setup

  • Go to the Google Developers Console
  • Click Continue. Then select Go to credentials and select Client ID
  • Under Application type, select Other and hit Create
  • Make a note of client ID and client secret
  • Navigate to auth folder cd /auth
  • run python3 auth_google.py -i <client-id> -s <client-secret>
  • This opens a popup in the browser. Authenticate and done!

Usage


Get your Google Developer Project Number (a 12 digit number) from a the Google Developers Console

Update project_number in config.ini to be your Google Developer Project Number.

Modify any other variables you'd like in config.ini with your own choices and start the sync using python3 app.py

Sync examples:

  • With date stamps : python3 app.py -s 2016-08-20 -e 2016-08-22
  • Last 3 days : python3 app.py -s "2 days ago" -e tomorrow
  • January month : python3 app.py -s "jan 1 2016" -e "feb 1 2016"

Setup autosync:

You can setup a cron task to automatically sync everyday at 2:30 AM.

30 2 * * * /path-to-repo/fitbit-googlefit/cron.sh >> /path-to-repo/fitbit-googlefit/cron.log 2>&1

Add above line to your cron tab: crontab -e in Linux. Sync logs will be stored to cron.log in repository.

Headless authentication


If you want to do the authentication process on a system without a display - such as a raspberry pi or a remote server, pass --console or -c option to the authentication scripts. See below examples.

python3 auth_fitbit.py -i clientid -s clientsecret --console

python3 auth_google.py -i clientid -s clientsecret --console

Note :

  1. Get command line help using the -h flag.
  2. Arguments passed through command-line take higher priority over config.ini values.

fitbit-googlefit's People

Contributors

bbagnall avatar davinkevin avatar dependabot[bot] avatar derekf35 avatar dwoffinden avatar grogdunn avatar lightmaster avatar madsmash avatar matt-boyd-pdx avatar nellh avatar nothingneko avatar pkpio avatar rdalin82 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fitbit-googlefit's Issues

[Question] about browser authentication

I'm writing a way for app.py to check if the authentication files already exist, and if they don't, to run the authentication scripts that are necessary. My copy is running headless on a Digital Ocean server, so I haven't run the script with the browser authentication method yet. The browser method does pause while you log into fitbit/google, and then continues after it gets a response, correct? I know the headless method waits until you type in the redirect url, just want to make sure the browser method also waits so I know if I need to add a pause after running that script.

My ultimate goal is that you download this program and just run app.py. The first time its run, it installs itself, gives you a chance to edit the config file, then runs the authentication scripts if the resulting files don't already exist. On subsequent runs, app.py sees that its already installed, config.ini has already been edit (if user wanted it edited), and both authentication files already exist, so it skips over all that and runs like normal.

Unable to authorise Fitbit

I try and authorise my Fitbit account, but it keeps on failing. I get the below error
I've tried recreating an application on Fitbit, but it doesn't work.
I've followed the youtube video as well. Please help. :)

[25/Jan/2017:21:24:33] ENGINE Started monitor thread 'Autoreloader'.
[25/Jan/2017:21:24:33] ENGINE Started monitor thread '_TimeoutMonitor'.
[25/Jan/2017:21:24:33] ENGINE Serving on http://127.0.0.1:8080
[25/Jan/2017:21:24:33] ENGINE Bus STARTED
127.0.0.1 - - [25/Jan/2017:21:25:35] "GET /?code=925c812757aa2c1d1kjjgkdb677d3f414bbc404e0&state=L4tw7ZXzkhmmms2VoiivVvB8zphB HTTP/1.1" 200 122 "" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.79 Safari/537.36 Edge/14.14393"
[25/Jan/2017:21:25:36] ENGINE Bus STOPPING
[25/Jan/2017:21:25:45] ENGINE HTTP Server cherrypy._cpwsgi_server.CPWSGIServer(('127.0.0.1', 8080)) shut down
[25/Jan/2017:21:25:45] ENGINE Stopped thread 'Autoreloader'.
[25/Jan/2017:21:25:45] ENGINE Stopped thread '_TimeoutMonitor'.
[25/Jan/2017:21:25:45] ENGINE Bus STOPPED
[25/Jan/2017:21:25:45] ENGINE Bus EXITING
[25/Jan/2017:21:25:45] ENGINE Bus EXITED
[25/Jan/2017:21:25:45] ENGINE Waiting for child threads to terminate...
Traceback (most recent call last):
File "auth_fitbit.py", line 109, in
main()
File "auth_fitbit.py", line 104, in main
access_token=server.oauth.token['access_token'],
AttributeError: 'FitbitOauth2Client' object has no attribute 'token'

Python Crashes upon sync

No error is given. Authentication is successful. however python crashes after entering python app.py.

Running Windows 10 and Python 3.5.4

API Limit Reached & Failure Upon Retry

ErrorLog.txt

  • API Limit resets on the hour. I think this has changed. Appears app retries after 15mins.
  • Upon retry I keep on getting errors, see attached.
  • I tried manually setting it to sleep for over an hour, but it still throws an error.

No distance and time in activities

First of all, thank you for the script, is really useful

But I found some issues: Steps and calories are synced correctly to Google Fit, but although the script reports me that also the distance has been synced, that's not true. I can't see any distance or time of activity. I use Fitbit with MobileTrack for counting the daily steps without starting any monitoring in the fitbit app, just for counting the steps, distance and estimated calories.

There is an screenshot showing how the calories are being synced
captura

Is strange how Google Fit works (I've already seen reports of this) but for the same day, in the calories view there are calories and in the step view there isn't.

captura

This isn't happening for the distance. If I switch to distance view, there is no distance at all. I thought that this script would sync the GPS positions in order to see the places I've been to also in Google Fit.

Thank you very much for this script!

Exercise distance not sync'd

I told the FitBit app on my phone to track my bike ride, which it did successfully. After finishing the tracking on my app, FitBit correctly reports the total distance biked, so the information is definitely available in FitBit. However, after I use the code in this project to sync FitBit over to Google Fit, that exercise activity shows up with a distance of 0 miles. The whole reason why I'm trying to sync is because I want to track total distance for all activities (walking, biking, etc.) every day and FitBit refuses to do that, so I want to use Google Fit for it. If exercise distances aren't sync'd, alas the sync'ing is useless to me. :-/

odd data accumulation issue when syncing several times per day

I have noticed that google mixes up data and puts out nonsensical values when you sync the same day several times (to update it through the course of the day). Should I just sync once? I further noticed that when I manually delete an activity on google, sometimes it just doesn't seem to delete it or put a different activity in its place (maybe that's a caching problem on Google's side?)

Google Fit Sync Error 403 -- "Application Package Name Provided By un-Trusted Source"

Hi -

This application has been fantastic for me. Thank you!

I've been able to use it to log Fitbit steps into Google Fit, and thus get a discount on my health insurance, which syncs with Google Fit, but not Fitbit. This is great!

I tried running the application today, and got this 403 error.

WARNING:googleapiclient.http:Encountered 403 Forbidden with reason "forbidden"
Traceback (most recent call last):
  File "app.py", line 110, in <module>
    main()
  File "app.py", line 75, in main
    remote.SyncFitbitToGoogleFit('steps',date_stamp)
  File "C:\fitbit-google\fitbit-googlefit-master\remote.py", line 145, in SyncFitbitToGoogleFit
    return self.SyncFitbitIntradayToGoogleFit(dataType, date_stamp)
  File "C:\fitbit-google\fitbit-googlefit-master\remote.py", line 188, in SyncFitbitIntradayToGoogleFit
    self.WriteToGoogleFit(dataSourceId, googlePoints)
  File "C:\fitbit-google\fitbit-googlefit-master\remote.py", line 91, in WriteToGoogleFit
    point=data_points)
  File "C:\Python36\lib\site-packages\oauth2client\util.py", line 137, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "C:\Python36\lib\site-packages\googleapiclient\http.py", line 840, in execute
    raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: <HttpError 403 when requesting https://www.googleapis.com/fitness/v1/users/me/dataSources/raw%3Acom.google.step_count.delta%3Afitbit%3Acharge-hr%3Aio.pkp.fbit-gfit/datasets/1536984000000000000-1537070340000000110?alt=json returned "Application package name () provided by un-trusted source.">

I've tried trouble-shooting this several ways, without success.

First, I deleted the google.json file in the auth folder, and re-ran the auth_google.py script. I was able to get the client ID & secret from the Google API console, which suggests the application was still recognized on their end. After re-creating the google.json file, I re-ran the app.py script, and the same error occurred.

Then I tried creating a new application on the Google side, following the instructions as before. I started by deleting google.json, then created the new application on Google's side, and then ran auth_google.py with the new application's client ID & secret. I re-ran app.py, and again got the same error.

How do I move forward from here?

app.py fails with ValueError: Missing access token.

Both Google and FitBit json auth files have been created using the utilities. Running app.py fails with the following trace:

Traceback (most recent call last):
File "app.py", line 108, in
main()
File "app.py", line 53, in main
userProfile = remote.ReadFromFitbit(fitbitClient.user_profile_get)
File "/home/jervine/git-checkouts/fitbit-googlefit/remote.py", line 54, in ReadFromFitbit
resp = api_call(*args,**kwargs)
File "/usr/lib/python3.5/site-packages/fitbit/api.py", line 256, in user_profile_get
return self.make_request(url)
File "/usr/lib/python3.5/site-packages/fitbit/api.py", line 227, in make_request
response = self.client.make_request(*args, **kwargs)
File "/usr/lib/python3.5/site-packages/fitbit/api.py", line 68, in make_request
response = self._request(method, url, data=data, auth=auth, **kwargs)
File "/usr/lib/python3.5/site-packages/fitbit/api.py", line 55, in _request
return self.session.request(method, url, **kwargs)
File "/usr/lib/python3.5/site-packages/requests/sessions.py", line 461, in request
prep = self.prepare_request(req)
File "/usr/lib/python3.5/site-packages/requests/sessions.py", line 394, in prepare_request
hooks=merge_hooks(request.hooks, self.hooks),
File "/usr/lib/python3.5/site-packages/requests/models.py", line 299, in prepare
self.prepare_auth(auth, url)
File "/usr/lib/python3.5/site-packages/requests/models.py", line 494, in prepare_auth
r = auth(self)
File "/usr/lib/python3.5/site-packages/requests_oauthlib/oauth2_auth.py", line 35, in call
http_method=r.method, body=r.body, headers=r.headers)
File "/usr/lib/python3.5/site-packages/oauthlib/oauth2/rfc6749/clients/base.py", line 191, in add_token
raise ValueError("Missing access token.")
ValueError: Missing access token.

Last step error

WARNING:googleapiclient.http:Encountered 403 Forbidden with reason "accessNotConfigured"

Cant authorize on FitBit API

Hello,

I tried to follow all steps explained and I get this error when trying to run python3 auth_fitbit.py <user_id> <user_secret>

I get the following error after seeing the success message on the callback url:
[26/Jan/2017:17:40:15] ENGINE Bus EXITED
[26/Jan/2017:17:40:15] ENGINE Waiting for child threads to terminate...
Traceback (most recent call last):
File "auth_fitbit.py", line 109, in
main()
File "auth_fitbit.py", line 104, in main
access_token=server.oauth.token['access_token'],
AttributeError: 'FitbitOauth2Client' object has no attribute 'token'

I guess some dependency has been updated and this doesn't work any more.

Thanks for the help

Steps wont show up on fit.google.com

First of all: I'm running your script on a Raspberry Pi.

I've used the workaround from #16 to login to fitbit and to login to google the --noauth_local_webserver flag.
For both I got the success-screen from http://localhost:8080/ and it seems that the sync was successful:

synced steps - 1440 data points
synced heart_rate - 0 data points

------------------------------   2017-02-19  -------------------------
synced steps - 1440 data points
synced heart_rate - 0 data points

------------------------------   2017-02-20  -------------------------
synced steps - 606 data points
synced heart_rate - 0 data points```

But when I login to https://fit.google.com I didn't see the steps on the dashboard.

I've tried it two times, with differenct Client-IDs/-secrets and it doesn't show up any steps/activities or any data on the google-fit dashboard.

I can't use the Google-Fit-App, so I have to use the web-version.

Request Too Large: When pushing data to Google Fit

When pushing the fitbit data to Google, I got the following (remote) exception.

rrs@learner:/var/tmp/lxc/fitbit-googlefit (master)$ python3 app.py 
------------------------------   2016-08-16  -------------------------
synced steps
synced distance
Traceback (most recent call last):
  File "app.py", line 107, in <module>
    main()
  File "app.py", line 85, in main
    remote.SyncFitbitToGoogleFit(fitbitClient,googleClient,'heart_rate',date_stamp,tzinfo)
  File "/media/SSHD/var/tmp/lxc/fitbit-googlefit/remote.py", line 112, in SyncFitbitToGoogleFit
    return SyncFitbitIntradayToGoogleFit(fitbitClient, googleClient, dataType, date_stamp, tzinfo)
  File "/media/SSHD/var/tmp/lxc/fitbit-googlefit/remote.py", line 149, in SyncFitbitIntradayToGoogleFit
    WriteToGoogleFit(googleClient, dataSourceId, googlePoints)
  File "/media/SSHD/var/tmp/lxc/fitbit-googlefit/remote.py", line 73, in WriteToGoogleFit
    point=data_points)
  File "/home/rrs/.local/lib/python3.5/site-packages/oauth2client/util.py", line 137, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "/home/rrs/.local/lib/python3.5/site-packages/googleapiclient/http.py", line 838, in execute
    raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: <HttpError 413 when requesting https://www.googleapis.com/fitness/v1/users/me/dataSources/raw%3Acom.google.heart_rate.bpm%3A558973839847%3Afitbit%3Acharge-hr%3Aio.pkp.fbit-gfit/datasets/1471285801000000000-1471372139000000110?alt=json returned "Request Too Large">
2016-08-18 / 15:19:31 ♒♒♒  ☹  => 1  

Maybe, because it is an initial sync of my Fitbit data. If so, this exception should be retried.

Update README on Google API

This would be very much appreciated. It seems like the Google API settings changed. I get completely lost there and can't get it to work.

No activities found after $DATE

I think the message here is misleading, because for sure it synced activities after the 19th ?

rrs@learner:~/.rrs-home/Community/fitbit-googlefit (master)$ ./cron.sh 
------------------------------   2016-08-19  -------------------------
synced steps
synced distance
synced heart_rate
synced weight
synced calories

------------------------------   2016-08-20  -------------------------
synced steps
synced distance
synced heart_rate
synced weight
synced calories

------------------------------   2016-08-21  -------------------------
synced steps
synced distance
synced heart_rate
synced weight
synced calories

------------------------------   2016-08-22  -------------------------
synced steps
synced distance
synced heart_rate
synced weight
synced calories

No activities found after 2016-08-19

2016-08-22 / 18:27:59 ♒♒♒  ☺  

no syncing

I discovered that the application doesn't sync with googleFit at all for two weeks now, at all, I don't know what is up with that.

Unchecked items

Are the unchecked items in the description - not checked because they cannot be synced to Google Fit or the software you created does not sync that data?

add some more documentation about sync range.

The default config.ini marks very recent. To sync all my fitibit data to GFit, I changed it to:

[params]

# Starting date of sync (inclusive)
start_date=2016-01-15

# Ending date of sync (exclusive)
end_date=2016-08-18

And it mostly works. Just that FitBit is throttling it.

rrs@learner:/var/tmp/lxc/fitbit-googlefit (master)$ python3 app.py 
------------------------------   2016-01-16  -------------------------
synced steps
synced distance
synced heart_rate
synced weight
synced calories

------------------------------   2016-01-17  -------------------------
synced steps
synced distance
synced heart_rate
synced weight
synced calories

------------------------------   2016-01-18  -------------------------
synced steps
synced distance
synced heart_rate
synced weight
synced calories

------------------------------   2016-01-19  -------------------------
synced steps
synced distance
synced heart_rate
synced weight
synced calories

------------------------------   2016-01-20  -------------------------
synced steps
synced distance
synced heart_rate
synced weight
synced calories

------------------------------   2016-01-21  -------------------------
synced steps
synced distance
synced heart_rate
synced weight
synced calories

------------------------------   2016-01-22  -------------------------
synced steps
synced distance
synced heart_rate
synced weight
synced calories

------------------------------   2016-01-23  -------------------------
synced steps
synced distance
synced heart_rate
synced weight
synced calories

------------------------------   2016-01-24  -------------------------
synced steps
synced distance
synced heart_rate
synced weight
synced calories

------------------------------   2016-01-25  -------------------------
synced steps
synced distance
synced heart_rate
synced weight
synced calories

------------------------------   2016-01-26  -------------------------
synced steps
synced distance
synced heart_rate
synced weight
synced calories

------------------------------   2016-01-27  -------------------------
synced steps
synced distance
synced heart_rate
synced weight
synced calories

------------------------------   2016-01-28  -------------------------
synced steps
synced distance
synced heart_rate
synced weight
synced calories

------------------------------   2016-01-29  -------------------------
synced steps
synced distance
synced heart_rate
synced weight
synced calories

------------------------------   2016-01-30  -------------------------
synced steps
synced distance
synced heart_rate
synced weight
synced calories

------------------------------   2016-01-31  -------------------------
synced steps
synced distance
synced heart_rate
synced weight
synced calories

------------------------------   2016-02-01  -------------------------
synced steps
synced distance
synced heart_rate
synced weight
synced calories

------------------------------   2016-02-02  -------------------------
synced steps
synced distance
synced heart_rate
synced weight
synced calories

------------------------------   2016-02-03  -------------------------
synced steps
synced distance
synced heart_rate
synced weight
synced calories

------------------------------   2016-02-04  -------------------------
synced steps
synced distance
synced heart_rate
synced weight
synced calories

------------------------------   2016-02-05  -------------------------
synced steps
synced distance
synced heart_rate
synced weight
synced calories

------------------------------   2016-02-06  -------------------------
synced steps
synced distance
synced heart_rate
synced weight
synced calories

------------------------------   2016-02-07  -------------------------
synced steps
synced distance
synced heart_rate
synced weight
synced calories

------------------------------   2016-02-08  -------------------------
synced steps
synced distance
synced heart_rate
synced weight
synced calories

------------------------------   2016-02-09  -------------------------
synced steps
synced distance
synced heart_rate
synced weight
synced calories

------------------------------   2016-02-10  -------------------------
synced steps
synced distance
synced heart_rate
synced weight
synced calories

------------------------------   2016-02-11  -------------------------
synced steps
synced distance
synced heart_rate
-------------- Fitbit API rate limit reached ----------
Will retry in 1953 seconds. Time now is : 2016-08-18 15:57:28.011781
synced weight
Traceback (most recent call last):
  File "app.py", line 107, in <module>
    main()
  File "app.py", line 97, in main
    remote.SyncFitbitToGoogleFit(fitbitClient,googleClient,'calories',date_stamp,tzinfo)
  File "/media/SSHD/var/tmp/lxc/fitbit-googlefit/remote.py", line 112, in SyncFitbitToGoogleFit
    return SyncFitbitIntradayToGoogleFit(fitbitClient, googleClient, dataType, date_stamp, tzinfo)
  File "/media/SSHD/var/tmp/lxc/fitbit-googlefit/remote.py", line 149, in SyncFitbitIntradayToGoogleFit
    WriteToGoogleFit(googleClient, dataSourceId, googlePoints)
  File "/media/SSHD/var/tmp/lxc/fitbit-googlefit/remote.py", line 73, in WriteToGoogleFit
    point=data_points)
  File "/home/rrs/.local/lib/python3.5/site-packages/oauth2client/util.py", line 137, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "/home/rrs/.local/lib/python3.5/site-packages/googleapiclient/http.py", line 833, in execute
    method=str(self.method), body=self.body, headers=self.headers)
  File "/home/rrs/.local/lib/python3.5/site-packages/googleapiclient/http.py", line 173, in _retry_request
    raise exception
  File "/home/rrs/.local/lib/python3.5/site-packages/googleapiclient/http.py", line 160, in _retry_request
    resp, content = http.request(uri, method, *args, **kwargs)
  File "/home/rrs/.local/lib/python3.5/site-packages/oauth2client/transport.py", line 169, in new_request
    redirections, connection_type)
  File "/home/rrs/.local/lib/python3.5/site-packages/httplib2/__init__.py", line 1314, in request
    (response, content) = self._request(conn, authority, uri, request_uri, method, body, headers, redirections, cachekey)
  File "/home/rrs/.local/lib/python3.5/site-packages/httplib2/__init__.py", line 1064, in _request
    (response, content) = self._conn_request(conn, request_uri, method, body, headers)
  File "/home/rrs/.local/lib/python3.5/site-packages/httplib2/__init__.py", line 988, in _conn_request
    conn.request(method, request_uri, body, headers)
  File "/usr/lib/python3.5/http/client.py", line 1106, in request
    self._send_request(method, url, body, headers)
  File "/usr/lib/python3.5/http/client.py", line 1151, in _send_request
    self.endheaders(body)
  File "/usr/lib/python3.5/http/client.py", line 1102, in endheaders
    self._send_output(message_body)
  File "/usr/lib/python3.5/http/client.py", line 936, in _send_output
    self.send(message_body)
  File "/usr/lib/python3.5/http/client.py", line 908, in send
    self.sock.sendall(data)
  File "/usr/lib/python3.5/ssl.py", line 891, in sendall
    v = self.send(data[count:])
  File "/usr/lib/python3.5/ssl.py", line 861, in send
    return self._sslobj.write(data)
  File "/usr/lib/python3.5/ssl.py", line 586, in write
    return self._sslobj.write(data)
BrokenPipeError: [Errno 32] Broken pipe
2016-08-18 / 16:30:03 ♒♒♒  ☹  => 1  

I think the exception can be ignored, as it looks mostly like a network error, which could be a temporary one on my laptop.

But, what are those start and end date about ? Does it mean we have to keep upping the end date ?

KeyError: 'activities-steps-intraday'

Hi, while trying to sync I get this error:

------------------------------ 2016-07-23 -------------------------
Traceback (most recent call last):
File "app.py", line 96, in
main()
File "app.py", line 67, in main
remote.SyncFitbitToGoogleFit('steps',date_stamp)
File "/home/mook/git/fitbit-googlefit/remote.py", line 125, in SyncFitbitToGoogleFit
return self.SyncFitbitIntradayToGoogleFit(dataType, date_stamp)
File "/home/mook/git/fitbit-googlefit/remote.py", line 153, in SyncFitbitIntradayToGoogleFit
intraday_data = interday_raw[resp_id]['dataset']
KeyError: 'activities-steps-intraday'

Google Fit to Fitbit?

How about syncing the other way? I'd like to add my google fit data to my Fitbit account...

Google API client error at first run

Installed on Ubuntu 17.10. Authenticating Fitbit and Google went fine. Run app.py and it throws some errors.
Here's the trace:

Traceback (most recent call last):
File "/home/dave/fitbit-googlefit/remote.py", line 122, in CreateGoogleFitDataSource
dataSourceId=self.convertor.GetDataSourceId(dataType)).execute()
File "/home/dave/.local/lib/python3.5/site-packages/oauth2client/util.py", line 137, in positional_wrapper
return wrapped(*args, **kwargs)
File "/home/dave/.local/lib/python3.5/site-packages/googleapiclient/http.py", line 840, in execute
raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: <HttpError 404 when requesting https://www.googleapis.com/fitness/v1/users/me/dataSources/raw%3Acom.google.step_count.delta%3A150600054579%3Afitbit%3Acharge-hr%3Aio.pkp.fbit-gfit?alt=json returned "DataSourceId not found: raw:com.google.step_count.delta:150600054579:fitbit:charge-hr:io.pkp.fbit-gfit">

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "app.py", line 110, in
main()
File "app.py", line 60, in main
remote.CreateGoogleFitDataSource(dataType)
File "/home/dave/fitbit-googlefit/remote.py", line 129, in CreateGoogleFitDataSource
body=self.convertor.GetDataSource(dataType)).execute()
File "/home/dave/.local/lib/python3.5/site-packages/oauth2client/util.py", line 137, in positional_wrapper
return wrapped(*args, **kwargs)
File "/home/dave/.local/lib/python3.5/site-packages/googleapiclient/http.py", line 840, in execute
raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: <HttpError 409 when requesting https://www.googleapis.com/fitness/v1/users/me/dataSources?alt=json returned "Data Source: raw:com.google.step_count.delta:fitbit:charge-hr:io.pkp.fbit-gfit already exists">

Any idea what could be the problem?
Thanks!

Walking activities from Fitbit are synchronized as aerobic

Hi there,

very nice script! But my walking activities from Fitbit are synchronized as aerobic (or something else) in Google Fit.
Also the sleep data from Fitbit are synchronized as "walk" sometimes.
Do you know this issue?

Best regards

Activity/Sleep mixup

First, this is a great achievement. I followed the instructions and got the app working within a few minutes. My Fitbit data is >1yr so I set it to synchronise all. Every 20days worth of data the Fitbit API would pause for 50 minutes, due to their rate limit policy. Less than 24 hours later all my data was synced.

The logs of heart rate, weight, calories, distance and steps look right. The logs of individual activities (walking in my case mostly) and sleep are inconsistent. Some activities are synced correctly, sometimes the activity is named 'Sleep' but has steps listed, sometimes the activity is listed as lasting 23hr59min and includes the whole day's steps.

I'm very happy to clear Google Fit and re-sync if you have any fixes in the pipeline. If I can help debug, let me know.

I took the code on 27th Aug, but I can't find a version. Can it have a -v option?

CherryPy error

I'm encountering a CherryPy error when attempting to authenticate with FitBit's api

`root@sync:/home/fitbit-googlefit-master/auth# python3 auth_fitbit.py 227YZF 7951c07a5b033aedff38ec6002703684
[14/Sep/2016:20:27:07] ENGINE Listening for SIGTERM.
[14/Sep/2016:20:27:07] ENGINE Listening for SIGUSR1.
[14/Sep/2016:20:27:07] ENGINE Listening for SIGHUP.
[14/Sep/2016:20:27:07] ENGINE Bus STARTING
CherryPy Checker:
The Application mounted at '' has an empty config.

[14/Sep/2016:20:27:07] ENGINE Started monitor thread '_TimeoutMonitor'.
[14/Sep/2016:20:27:07] ENGINE Started monitor thread 'Autoreloader'.
[14/Sep/2016:20:27:12] ENGINE Error in 'start' listener <bound method Server.start of <cherrypy._cpserver.Server object at 0x7effd5aeba58>>
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/cherrypy/process/wspbus.py", line 205, in publish
output.append(listener(_args, *_kwargs))
File "/usr/local/lib/python3.5/dist-packages/cherrypy/_cpserver.py", line 168, in start
ServerAdapter.start(self)
File "/usr/local/lib/python3.5/dist-packages/cherrypy/process/servers.py", line 170, in start
wait_for_free_port(*self.bind_addr)
File "/usr/local/lib/python3.5/dist-packages/cherrypy/process/servers.py", line 439, in wait_for_free_port
raise IOError("Port %r not free on %r" % (port, host))
OSError: Port 8080 not free on '127.0.0.1'

[14/Sep/2016:20:27:12] ENGINE Shutting down due to error in start listener:
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/cherrypy/process/wspbus.py", line 243, in start
self.publish('start')
File "/usr/local/lib/python3.5/dist-packages/cherrypy/process/wspbus.py", line 223, in publish
raise exc
cherrypy.process.wspbus.ChannelFailures: OSError("Port 8080 not free on '127.0.0.1'",)

[14/Sep/2016:20:27:12] ENGINE Bus STOPPING
[14/Sep/2016:20:27:12] ENGINE HTTP Server cherrypy._cpwsgi_server.CPWSGIServer(('127.0.0.1', 8080)) already shut down
[14/Sep/2016:20:27:12] ENGINE Stopped thread '_TimeoutMonitor'.
[14/Sep/2016:20:27:12] ENGINE Stopped thread 'Autoreloader'.
[14/Sep/2016:20:27:12] ENGINE Bus STOPPED
[14/Sep/2016:20:27:12] ENGINE Bus EXITING
[14/Sep/2016:20:27:12] ENGINE Bus EXITED
`

Is my suspicion that the problem is somewhere outside the fitbit-googlefit app correct? Should I be looking at my server configuration instead of the app to find the problem?

REM State sync

I previously owned a Fitbit device and sold it because its closed environment. Now I'm thinking on getting one back provided that this allows me to sync most of my data to Google Fit but I have one questions.

Would this script allow me to sync the new sleep states that Fitbit implemented? REM sleep and the kind.

Thanks a lot for your help!

googleapiclient.errors returned "Request Too Large"

Hello,
I am tring to import the data to Google Fitness but it start to give me this error, why?
Thank you very much

synced steps
synced distance
Traceback (most recent call last):
File "app.py", line 96, in
main()
File "app.py", line 75, in main
remote.SyncFitbitToGoogleFit('heart_rate',date_stamp)
File "/home/diego/Downloads/fitbit-googlefit/remote.py", line 125, in SyncFitbitToGoogleFit
return self.SyncFitbitIntradayToGoogleFit(dataType, date_stamp)
File "/home/diego/Downloads/fitbit-googlefit/remote.py", line 159, in SyncFitbitIntradayToGoogleFit
self.WriteToGoogleFit(dataSourceId, googlePoints)
File "/home/diego/Downloads/fitbit-googlefit/remote.py", line 85, in WriteToGoogleFit
).execute()
File "/usr/local/lib/python3.4/dist-packages/oauth2client/util.py", line 137, in positional_wrapper
return wrapped(_args, *_kwargs)
File "/usr/local/lib/python3.4/dist-packages/googleapiclient/http.py", line 838, in execute
raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: <HttpError 413 when requesting https://www.googleapis.com/fitness/v1/users/me/dataSources/raw%3Acom.google.heart_rate.bpm%3A26454365833%3Afitbit%3Acharge-hr%3Aio.pkp.fbit-gfit/datasets/1467154800000000000-1467241139000000110?alt=json returned "Request Too Large">

fitbit auth script needs an option to auth from headless box

I'm trying to set this sync utility u on a box that has no graphical environment.

In order to get the fitbit auth URL, i had to change line 55
https://github.com/praveendath92/fitbit-googlefit/blob/master/auth/auth_fitbit.py#L55

to

        #threading.Timer(1, webbrowser.open, args=(url,)).start()
        print(url)

which does not attempt to open the systems browser and just puts the auth URL on the console so i can open it on a device that does to obtain the fitbit auth token.

KeyError: 'activities-steps-intraday'

Hello,
I just start to use this project to export the Fitbit data to Google Fit. I installed it and I am trying to export the data for the first time. However, I have this error:

python3 app.py -s "4 days ago" -e tomorrow
------------------------------ 2016-08-22 -------------------------
Traceback (most recent call last):
File "app.py", line 96, in
main()
File "app.py", line 67, in main
remote.SyncFitbitToGoogleFit('steps',date_stamp)
File "/home/diego/Downloads/fitbit-googlefit/remote.py", line 125, in SyncFitbitToGoogleFit
return self.SyncFitbitIntradayToGoogleFit(dataType, date_stamp)
File "/home/diego/Downloads/fitbit-googlefit/remote.py", line 153, in SyncFitbitIntradayToGoogleFit
intraday_data = interday_raw[resp_id]['dataset']
KeyError: 'activities-steps-intraday'

How can I solve it?
Thank you

Data Source: raw:com.google.step_count.delta:fitbit:charge-hr:io.pkp.fbit-gfit already exists

Haven't used it a while and noticed my cron job stopped working due to expired API key and updated python version. Authed again for both Google and Fitbit, but not working.

fitbit-googlefit (master) /usr/local/bin/python3 /Users/rolle/fitbit-googlefit/app.py

Traceback (most recent call last):
  File "/Users/rolle/fitbit-googlefit/remote.py", line 119, in CreateGoogleFitDataSource
    dataSourceId=self.convertor.GetDataSourceId(dataType)).execute()
  File "/usr/local/lib/python3.6/site-packages/oauth2client/util.py", line 137, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/googleapiclient/http.py", line 840, in execute
    raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: <HttpError 404 when requesting https://www.googleapis.com/fitness/v1/users/me/dataSources/raw%3Acom.google.step_count.delta%3A191719253163%3Afitbit%3Acharge-hr%3Aio.pkp.fbit-gfit?alt=json returned "DataSourceId not found: raw:com.google.step_count.delta:191719253163:fitbit:charge-hr:io.pkp.fbit-gfit">

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/rolle/fitbit-googlefit/app.py", line 108, in <module>
    main()
  File "/Users/rolle/fitbit-googlefit/app.py", line 59, in main
    remote.CreateGoogleFitDataSource(dataType)
  File "/Users/rolle/fitbit-googlefit/remote.py", line 126, in CreateGoogleFitDataSource
    body=self.convertor.GetDataSource(dataType)).execute()
  File "/usr/local/lib/python3.6/site-packages/oauth2client/util.py", line 137, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/googleapiclient/http.py", line 840, in execute
    raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: <HttpError 409 when requesting https://www.googleapis.com/fitness/v1/users/me/dataSources?alt=json returned "Data Source: raw:com.google.step_count.delta:fitbit:charge-hr:io.pkp.fbit-gfit already exists">

Can you help me to resolve this?

Google Fit steps being overwritten

Great app!

I use both my phone and my Fitbit separately throughout the day depending on the circumstances. I noticed that when I run this sync program, it overwrites all of the steps data on Google Fit.

The other apps that I have used that sync steps with Google Fit seem to be smarter and only overwrite for the time period the steps occurred and not the whole day. Is it possible to facilitate this?

Thank you!
Ken

PS, the instructions for the Google API need to be updated. They have changed their requirements.

auth_google.py changes to remove local webserver requirement

A suggestion for improvement:
In setting up the Google authentication on a GUI-less machine, the auth_google.py script throws an option for "--noauth_local_webserver", but the way auth_google.py is coded, it doesn't actually work. So, here's a suggestion for improvement that uses the oauth2 parser and adds a few arguments.

!/usr/bin/env python
import sys, argparse

from oauth2client.file import Storage
from oauth2client.client import OAuth2WebServerFlow
from oauth2client.tools import run_flow, argparser

def main():
  parser = argparse.ArgumentParser(parents=[argparser])
  parser.add_argument('client_id')
  parser.add_argument('client_secret')

  # Scopes of authorization
  activity = "https://www.googleapis.com/auth/fitness.activity.write"
  body = "https://www.googleapis.com/auth/fitness.body.write"
  location = "https://www.googleapis.com/auth/fitness.location.write"
  scopes = activity + " " + body + " " + location

  flags = parser.parse_args()
  flow = OAuth2WebServerFlow(flags.client_id, flags.client_secret, scopes)
  storage = Storage('google.json')
  run_flow(flow, storage, flags)

if __name__ == '__main__':
  main()

This slight modification in the code now properly parses the "--noauth_local_webserver" out of the args no matter the order when entered in the command line.

Running app.py fails

First time install & run. I was successful with authorizing both FitBit & GFit with fitbit.json and google.json generated). When I run app.py though, I get the following error:

------------------------------   2017-01-26  -------------------------
Traceback (most recent call last):
  File "app.py", line 108, in <module>
    main()
  File "app.py", line 74, in main
    remote.SyncFitbitToGoogleFit('steps',date_stamp)
  File "/Users/ggrell/Projects/fitbit-googlefit/remote.py", line 139, in SyncFitbitToGoogleFit
    self.helper.UpdateFitbitCredentials(self.fitbitClient)
  File "/Users/ggrell/Projects/fitbit-googlefit/helpers.py", line 50, in UpdateFitbitCredentials
    credentials[t] = fitbitClient.client.token[t]
AttributeError: 'FitbitOauth2Client' object has no attribute 'token'

Mac OS 10.11.6 (El Cap)
Python 3.6.0 installed via HomeBrew

NameError: name 'googleClient' is not defined

Good day, in first place thanks for this piece of software.

When i launch "python3 app.py -s 2016-08-15 -e 2016-08-21"

it returns this:

` File "/home/perdido/programmi/fitbit-googlefit-master/remote.py", line 102, in CreateGoogleFitDataSource
dataSourceId=self.convertor.GetDataSourceId(dataType)).execute()
File "/usr/local/lib/python3.5/dist-packages/oauth2client/util.py", line 137, in positional_wrapper
return wrapped(_args, *_kwargs)
File "/usr/local/lib/python3.5/dist-packages/googleapiclient/http.py", line 838, in execute
raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: <HttpError 404 when requesting https://www.googleapis.com/fitness/v1/users/me/dataSources/raw%3Acom.google.step_count.delta%3A676930878379%3Afitbit%3Acharge-hr%3Aio.pkp.fbit-gfit?alt=json returned "DataSourceId not found: raw:com.google.step_count.delta:676930878379:fitbit:charge-hr:io.pkp.fbit-gfit">

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "app.py", line 96, in
main()
File "app.py", line 52, in main
remote.CreateGoogleFitDataSource(dataType)
File "/home/perdido/programmi/fitbit-googlefit-master/remote.py", line 107, in CreateGoogleFitDataSource
googleClient.users().dataSources().create(
NameError: name 'googleClient' is not defined
`
I've got the two files correctly for the auth2 api usage, but i've just setup the google fit account.
i need to do something to inizialize? i've run through the setup, enable everything it asks me to enable and set up an objective, is it enough?
Because it seems a call to something that not exist related to google fit... but maybe i'm wrong

Thanks

Sync a on a Pi with Raspbian

Not a real issue (for me), works on my mac (like a charm, great work) but just to inform you, on my raspberry pi got this message:

$ python3 app.py -s "2 days ago" -e tomorrow
Traceback (most recent call last):
  File "app.py", line 17, in <module>
    from helpers import *
  File "/home/pi/fitbit-googlefit/helpers.py", line 8, in <module>
    import fitbit
ImportError: No module named fitbit

Totally no experience w python, so maybe it's a small thing.

exception with body_fat data type

Hi, Thanks for creating this bridge.
When trying to run app.py, I've run into the following exception. I did setup the fitbit/google authentication successfully, as you've documented.

rrs@learner:/var/tmp/lxc/fitbit-googlefit (master)$ python3 app.py 
Traceback (most recent call last):
  File "app.py", line 60, in main
    googleClient.users().dataSources().get(userId='me',dataSourceId=dataSourceId).execute()
  File "/usr/lib/python3/dist-packages/oauth2client/util.py", line 137, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/googleapiclient/http.py", line 832, in execute
    raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: <HttpError 404 when requesting https://www.googleapis.com/fitness/v1/users/me/dataSources/raw%3Acom.google.body.fat.percentage%3A558973839847%3Afitbit%3Aaria%3Aio.pkp.fbit-gfit?alt=json returned "DataSourceId not found: raw:com.google.body.fat.percentage:558973839847:fitbit:aria:io.pkp.fbit-gfit">

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "app.py", line 113, in <module>
    main()
  File "app.py", line 65, in main
    googleClient.users().dataSources().create(userId='me',body=helper.GetDataSource(dataType)).execute()
  File "/usr/lib/python3/dist-packages/oauth2client/util.py", line 137, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/googleapiclient/http.py", line 832, in execute
    raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: <HttpError 400 when requesting https://www.googleapis.com/fitness/v1/users/me/dataSources?alt=json returned "Bad Request">
2016-08-18 / 13:59:09 ♒♒♒  ☹  => 1  

ValueError: Missing access token.

Hi there,

I'm setting this up on a Raspberry Pi. I have successfully authenticated (locally on the pi) on both the Fitbit and Google ends. However, when I try to run the app remotely over SSH I get the following error:

sudo python3 app.py

Traceback (most recent call last):
File "app.py", line 110, in
main()
File "app.py", line 54, in main
userProfile = remote.ReadFromFitbit(fitbitClient.user_profile_get)
File "/home/pi/Documents/fitbitenv/fitbit-googlefit/remote.py", line 55, in ReadFromFitbit
resp = api_call(*args,**kwargs)
File "/usr/local/lib/python3.4/dist-packages/fitbit/api.py", line 256, in user_profile_get
return self.make_request(url)
File "/usr/local/lib/python3.4/dist-packages/fitbit/api.py", line 227, in make_request
response = self.client.make_request(*args, **kwargs)
File "/usr/local/lib/python3.4/dist-packages/fitbit/api.py", line 68, in make_request
response = self._request(method, url, data=data, auth=auth, **kwargs)
File "/usr/local/lib/python3.4/dist-packages/fitbit/api.py", line 55, in _request
return self.session.request(method, url, **kwargs)
File "/usr/local/lib/python3.4/dist-packages/requests/sessions.py", line 499, in request
prep = self.prepare_request(req)
File "/usr/local/lib/python3.4/dist-packages/requests/sessions.py", line 431, in prepare_request
hooks=merge_hooks(request.hooks, self.hooks),
File "/usr/local/lib/python3.4/dist-packages/requests/models.py", line 307, in prepare
self.prepare_auth(auth, url)
File "/usr/local/lib/python3.4/dist-packages/requests/models.py", line 538, in prepare_auth
r = auth(self)
File "/usr/local/lib/python3.4/dist-packages/requests_oauthlib/oauth2_auth.py", line 35, in call
http_method=r.method, body=r.body, headers=r.headers)
File "/usr/local/lib/python3.4/dist-packages/oauthlib/oauth2/rfc6749/clients/base.py", line 191, in add_token
raise ValueError("Missing access token.")
ValueError: Missing access token.

I have also tried running it locally with the same error. The fitbit and google json files are in the auth folder and seem to have the appropriate values in them. Apologies if there is an obvious answer to this but I'm a bit lost here!

Cheers,
Ben

Authentication failing

I followed all the steps in github and even youtube video successfully but the authentication is failing. fitbit.json and google.json have also been created successfully. access token in fitbit.json is null.

C:\Desktop\Mydocs\Fitbit-google\fitbit-googlefit-master\fitbit-googlefit-master>python app.py --debug

Traceback (most recent call last):
File "app.py", line 110, in
main()
File "app.py", line 54, in main
userProfile = remote.ReadFromFitbit(fitbitClient.user_profile_get)
File "C:\Users\anainwal\Desktop\Mydocs\Fitbit-google\fitbit-googlefit-master\fitbit-googlefit-master\remote.py", line 55, in ReadFromFitbit
resp = api_call(*args,**kwargs)
File "C:\Users\anainwal\AppData\Local\Programs\Python\Python36\lib\site-packages\fitbit\api.py", line 256, in user_profile_get
return self.make_request(url)
File "C:\Users\anainwal\AppData\Local\Programs\Python\Python36\lib\site-packages\fitbit\api.py", line 227, in make_request
response = self.client.make_request(*args, **kwargs)
File "C:\Users\anainwal\AppData\Local\Programs\Python\Python36\lib\site-packages\fitbit\api.py", line 68, in make_request
response = self._request(method, url, data=data, auth=auth, **kwargs)
File "C:\Users\anainwal\AppData\Local\Programs\Python\Python36\lib\site-packages\fitbit\api.py", line 55, in _request
return self.session.request(method, url, **kwargs)
File "C:\Users\anainwal\AppData\Local\Programs\Python\Python36\lib\site-packages\requests\sessions.py", line 499, in request
prep = self.prepare_request(req)
File "C:\Users\anainwal\AppData\Local\Programs\Python\Python36\lib\site-packages\requests\sessions.py", line 431, in prepare_request
hooks=merge_hooks(request.hooks, self.hooks),
File "C:\Users\anainwal\AppData\Local\Programs\Python\Python36\lib\site-packages\requests\models.py", line 307, in prepare
self.prepare_auth(auth, url)
File "C:\Users\anainwal\AppData\Local\Programs\Python\Python36\lib\site-packages\requests\models.py", line 538, in prepare_auth
r = auth(self)
File "C:\Users\anainwal\AppData\Local\Programs\Python\Python36\lib\site-packages\requests_oauthlib\oauth2_auth.py", line 35, in call
http_method=r.method, body=r.body, headers=r.headers)
File "C:\Users\anainwal\AppData\Local\Programs\Python\Python36\lib\site-packages\oauthlib\oauth2\rfc6749\clients\base.py", line 191, in add_token
raise ValueError("Missing access token.")
ValueError: Missing access token.

Error on running script

Hi, I get the following error when executing:

Traceback (most recent call last):
  File "/Users/paul/Software/GitHub/fitbit-googlefit/remote.py", line 122, in CreateGoogleFitDataSource
    dataSourceId=self.convertor.GetDataSourceId(dataType)).execute()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/oauth2client/util.py", line 137, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/googleapiclient/http.py", line 840, in execute
    raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: <HttpError 404 when requesting https://www.googleapis.com/fitness/v1/users/me/dataSources/raw%3Acom.google.step_count.delta%3Afitbit%3Acharge-hr%3Aio.pkp.fbit-gfit?alt=json returned "DataSourceId not found: raw:com.google.step_count.delta:fitbit:charge-hr:io.pkp.fbit-gfit">

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "app.py", line 110, in <module>
    main()
  File "app.py", line 60, in main
    remote.CreateGoogleFitDataSource(dataType)
  File "/Users/paul/Software/GitHub/fitbit-googlefit/remote.py", line 129, in CreateGoogleFitDataSource
    body=self.convertor.GetDataSource(dataType)).execute()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/oauth2client/util.py", line 137, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/googleapiclient/http.py", line 840, in execute
    raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: <HttpError 409 when requesting https://www.googleapis.com/fitness/v1/users/me/dataSources?alt=json returned "Data Source: raw:com.google.step_count.delta:453688148430:fitbit:charge-hr:io.pkp.fbit-gfit already exists">

Any idea what I have configured incorrectly?

Thanks!

Paul

DataPoint out of range: com.google.step_count.delta

Sync has stopped working for me since ~26th September.
I'm seeing the following error:
googleapiclient.errors.HttpError: <HttpError 400 when requesting https://www.googleapis.com/fitness/v1/users/me/dataSources/raw%3Acom.google.step_count.delta%3Aprojid%3Afitbit%3Acharge-hr%3Aio.pkp.fbit-gfit/datasets/1569420000000000000-1569506340000000110?alt=json returned "DataPoint out of range: com.google.step_count.delta [2019-09-25T16:48:00Z - 2019-09-25T16:48:00.000000110Z] [5] raw:com.google.step_count.delta:projid:fitbit:charge-hr:io.pkp.fbit-gfit">

It's not just one data set that's broken. If I try to sync any day, then it will report the same error.
I've done a bit of debugging, and there doesn't seem like there's anything wrong with the data - this is the one that corresponds to the UTC timestamp (2019-09-25T16:48:00Z):
StepsPoint timestamp=2019-09-26 02:48:00 epoch=1569430080000000000 data_point=5
The biggest value for step_count.delta was 120 (at epoch=1569478560000000000).

The only info I found about "DataPoint out of range" is:
https://stackoverflow.com/questions/47532849/add-google-fit-distance-datapoint-out-of-range

Is it somehow not representing that set of data as a 1 minute sample?
Any ideas what to check?

Filter Driving activities

Hello, I use my Fitbit Charge 2 to log my steps. Unfortunately when cycling extra steps are wrongly added to my daily steps total. The only workaround is to add a "Driving" activity for the time I was cycling and then Fitbit deletes the false steps. Unfortunately when the "Driving" activity syncs to Google Fit it then intefers with the cycling activity uploaded by Strava. Would it be possible to filter Driving activitys from syncing?

Fitbit steps being listed as manual google fit step entries

I wear my fitbit all the time but don't always have my phone with me. If I get 10,000 steps on my fitbit and then sync using your incredibly helpful code, the steps show up as 'misc steps' and do not count as part of my 10,000 step goal set on google fit.

Any way to solve this?

screenshot_20170801-164157

exception KeyError: 'activities-steps-intraday' when trying to sync

While working on #1, the next gradual exception is got is:

rrs@learner:/var/tmp/lxc/fitbit-googlefit (master)$ python3 app.py 
------------------------------   2016-08-16  -------------------------
Traceback (most recent call last):
  File "app.py", line 107, in <module>
    main()
  File "app.py", line 77, in main
    remote.SyncFitbitToGoogleFit(fitbitClient,googleClient,'steps',date_stamp,tzinfo)
  File "/media/SSHD/var/tmp/lxc/fitbit-googlefit/remote.py", line 112, in SyncFitbitToGoogleFit
    return SyncFitbitIntradayToGoogleFit(fitbitClient, googleClient, dataType, date_stamp, tzinfo)
  File "/media/SSHD/var/tmp/lxc/fitbit-googlefit/remote.py", line 143, in SyncFitbitIntradayToGoogleFit
    intraday_data = interday_raw[resp_id]['dataset']
KeyError: 'activities-steps-intraday'
2016-08-18 / 14:46:48 ♒♒♒  ☹  => 1  

Error during first usage of the app

Hi,

I followed the auth process very carefully and all went well, but when I launch for the first time the app.py, I've got the following result:

python3 app.py --debug

Traceback (most recent call last):
  File "/project/remote.py", line 122, in CreateGoogleFitDataSource
    dataSourceId=self.convertor.GetDataSourceId(dataType)).execute()
  File "/usr/local/lib/python3.6/site-packages/oauth2client/util.py", line 137, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/googleapiclient/http.py", line 840, in execute
    raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: <HttpError 404 when requesting https://www.googleapis.com/fitness/v1/users/me/dataSources/raw%3Acom.google.step_count.delta%3A470777633164%3Afitbit%3Acharge-hr%3Aio.pkp.fbit-gfit?alt=json returned "DataSourceId not found: raw:com.google.step_count.delta:470777633164:fitbit:charge-hr:io.pkp.fbit-gfit">

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "app.py", line 110, in <module>
    main()
  File "app.py", line 60, in main
    remote.CreateGoogleFitDataSource(dataType)
  File "/project/remote.py", line 129, in CreateGoogleFitDataSource
    body=self.convertor.GetDataSource(dataType)).execute()
  File "/usr/local/lib/python3.6/site-packages/oauth2client/util.py", line 137, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/googleapiclient/http.py", line 840, in execute
    raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: <HttpError 409 when requesting https://www.googleapis.com/fitness/v1/users/me/dataSources?alt=json returned "Data Source: raw:com.google.step_count.delta:fitbit:charge-hr:io.pkp.fbit-gfit already exists">

I don't know what to do to help solve this problem

Thanks

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.