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 during first usage of the app #51

Closed davinkevin closed 6 years ago

davinkevin commented 6 years ago

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

ericzinnikas commented 6 years ago

I had some success manually deleting the DataSource (works on next run after this):

curl --header "Authorization: Bearer ya29.SECRETHERE" -X DELETE \ 
--header "Content-Type: application/json;encoding=utf-8"  \ 
"https://www.googleapis.com/fitness/v1/users/me/dataSources/raw:com.google.body.fat.percentage:fitbit:aria:io.pkp.fbit-gfit"

But then I'm running into errors about:

googleapiclient.errors.HttpError: <HttpError 400 when requesting https://www.googleapis.com/fitness/v1/users/me/dataSources/raw%3Acom.google.weight%3AXXXXXXXX%3Afitbit%3Aaria%3Aio.pkp.fbit-gfit/datasets/1519720264000000000-1519720264000000110?alt=json returned "Unable to fetch DataSource for Dataset: raw:com.google.weight:312047935529:fitbit:aria:io.pkp.fbit-gfit">

Though if I manually issue the curl request, it completes successfully. So either Google's API is having issues or the python wrapper is buggy it would seem? I'm not sure.

ericzinnikas commented 6 years ago

Alright, after a bunch more debugging... open up convertors.py and comment out line 355:

- projectNumber,
+ #projectNumber,

Looking at Google Fit on my phone after, I can see that weight definitely has synced (that's the only one I tried).

ericzinnikas commented 6 years ago

No idea why this works... their API docs seem to say this should not work, but it obviously does.

pkpio commented 6 years ago

@ericzinnikas Thanks for digging in. Sorry, I didn't get a chance to look into this lately. I will find a proper fix when I revisit the project.

davinkevin commented 6 years ago

Thx for the help, I will try that as soon as possible !

davinkevin commented 6 years ago

This totally solves the problem without even delete the previous element

mollerhansen commented 6 years ago

my line 355 in converters.py are: dataSource['device']['manufacturer'],

But I am getting the same error, any good suggestions?

ericzinnikas commented 6 years ago

See my comment above, it is line 354 now (the "projectNumber," line).

tvdsluijs commented 6 years ago

I've got the same error.

Traceback (most recent call last):
  File "/Users/theovandersluijs/PycharmProjects/fitbit-googlefit/remote.py", line 122, in CreateGoogleFitDataSource
    dataSourceId=self.convertor.GetDataSourceId(dataType)).execute()
  File "/Users/theovandersluijs/PycharmProjects/fitbitenv/lib/python3.6/site-packages/oauth2client/util.py", line 137, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "/Users/theovandersluijs/PycharmProjects/fitbitenv/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%3A984249661236%3Afitbit%3Acharge-hr%3Aio.pkp.fbit-gfit?alt=json returned "DataSourceId not found: raw:com.google.step_count.delta:984249661236: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/theovandersluijs/PycharmProjects/fitbit-googlefit/remote.py", line 129, in CreateGoogleFitDataSource
    body=self.convertor.GetDataSource(dataType)).execute()
  File "/Users/theovandersluijs/PycharmProjects/fitbitenv/lib/python3.6/site-packages/oauth2client/util.py", line 137, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "/Users/theovandersluijs/PycharmProjects/fitbitenv/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">
pkpio commented 6 years ago

Resolved in #58