pkpio / fitbit-googlefit

Export Fitbit data to Google Fit. Unlike the alternatives such as fitnessyncer.com, this offers very fine intraday granularity (every minute/second data).
http://pkp.io/blog/fitbit-to-googlefit-sync/
GNU General Public License v3.0
500 stars 59 forks source link

Error on running script #61

Closed thundercatsNZ closed 3 years ago

thundercatsNZ commented 6 years ago

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

bbagnall commented 6 years ago

The problem is with the IDs that the project generates. Google requires that they are formatted like:

type:dataType.name:developer-project-number:device.manufacturer:device.model:device.uid:dataStreamName 

reference but the code doesn't include the project number.

You can get your project number in the Google Developers Console in a spot like: https://console.developers.google.com/iam-admin/settings?project=

Assuming your project id was: 123456789012, you can fix the code by modifying the end of converters.py

Change it from:

        return ':'.join((
            dataSource['type'],
            dataSource['dataType']['name'],
            dataSource['device']['manufacturer'],
            dataSource['device']['model'],
            dataSource['device']['uid']))

to

        return ':'.join((
            dataSource['type'],
            dataSource['dataType']['name'],
                         '123456789012',
            dataSource['device']['manufacturer'],
            dataSource['device']['model'],
            dataSource['device']['uid']))
Grogdunn commented 6 years ago

This revert 6c095dacf2c190aec341bd6249c524b3eefd65c5 commit. But the issue #57 it will be open again.

What do you think?

bbagnall commented 6 years ago

The commit you referenced is cleaner than my way, and doesn't require user interaction to modify the config.

When I ran the code in master branch, it generated: raw:com.google.step_count.delta:<obfuscated-projec-number>:fitbit:charge-hr:<obfuscated-uid>

I could see them by going to: https://developers.google.com/apis-explorer/#search/fitness.users.datasources.list/m/fitness/v1/fitness.users.dataSources.list?userId=me

I'm not sure how it got created to cause the error on the first run of the code, but for all later runs, it failed because the DataSourceId generated wasn't correct, so it can't find it, and it tries to create it again.

ronilaukkarinen commented 5 years ago

I have the same problem, 403... :/

pkpio commented 3 years ago

I believe this issue should be resolved by the recent changes in the repo. Please reopen if not.