Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Cédric Bonhomme
    @cedricbonhomme
    This message was deleted

    Hi,

    I am using the fitbit module in order to retrieve my data and to plot it with matplotlib (https://github.com/cedricbonhomme/health). It's working quite well. Later the data will be stored in a database. But for the moment, I just plot it... My problem is that now I have to renew the access token.

    Here is my code:

    My code:

    client_kwargs = {
            'client_id': CLIENT_KEY,
            'client_secret': CLIENT_SECRET,
            'callback_uri': 'https://dev.fitbit.com',
            'scope': ['sleep+settings+nutrition+activity+social+heartrate+profile+weight+location']
    }
    client_kwargs['access_token'] = ACCESS_TOKEN
    client_kwargs['refresh_token'] = REFRESH_TOKEN
    
    fb = fitbit.Fitbit(CLIENT_KEY, CLIENT_SECRET, oauth2=True, access_token=ACCESS_TOKEN, refresh_token=REFRESH_TOKEN)
    #fb = fitbit.Fitbit(**client_kwargs)
    retval = fb.client.refresh_token()

    And so I get:

    $ python3.5 refresh_token.py 
    Traceback (most recent call last):
      File "refresh_token.py", line 33, in <module>
        retval = fb.client.refresh_token()
      File "/usr/local/lib/python3.5/site-packages/fitbit/api.py", line 163, in refresh_token
        auth=requests.auth.HTTPBasicAuth(self.client_id, self.client_secret)
      File "/usr/local/lib/python3.5/site-packages/requests_oauthlib/oauth2_session.py", line 309, in refresh_token
        self.token = self._client.parse_request_body_response(r.text, scope=self.scope)
      File "/usr/local/lib/python3.5/site-packages/oauthlib/oauth2/rfc6749/clients/base.py", line 409, in parse_request_body_response
        self.token = parse_token_response(body, scope=scope)
      File "/usr/local/lib/python3.5/site-packages/oauthlib/oauth2/rfc6749/parameters.py", line 376, in parse_token_response
        validate_token_parameters(params)
      File "/usr/local/lib/python3.5/site-packages/oauthlib/oauth2/rfc6749/parameters.py", line 386, in validate_token_parameters
        raise MissingTokenError(description="Missing access token parameter.")
    oauthlib.oauth2.rfc6749.errors.MissingTokenError: (missing_token) Missing access token parameter.

    I do not see a fundamental difference with https://github.com/pedrobpio/demo-python-fitbit/blob/master/demo-2.py#L101 .

    Concerning your variable userid = f.readline() (https://github.com/pedrobpio/demo-python-fitbit/blob/master/demo-2.py#L95), why don't you use the one stored in config.ini ? Does the client_id (the OAuth 2.0 Client ID) change?

    thanks,

    Cédric

    I hope that I posted the message to the good place. I usually don't use gitter.
    Cédric Bonhomme
    @cedricbonhomme
    I am using the version of fitbit from pypi. But I just checked with the version from the master branch. Same problem.
    Brad Pitcher
    @brad
    This is a great place @cedricbonhomme It is exactly why we created the room :smile:
    Let me think about this a bit
    Cédric Bonhomme
    @cedricbonhomme
    ok, thanks a lot!
    Brad Pitcher
    @brad
    @cedricbonhomme What version of requests-oauthlib do you have?
    Aaron Wolen
    @aaronwolen
    I also get the same error as @cedricbonhomme with fitbit 0.2.3 and requests-oauthlib 0.6.2.
    Aaron Wolen
    @aaronwolen
    Although one notable difference, I'm running Python 2.7.12.
    Cédric Bonhomme
    @cedricbonhomme
    a reply from @pedrobpio : https://github.com/orcasgit/python-fitbit/issues/94#issuecomment-245920772 . I do not know what I am doing wrong.
    I am using requests-oauthlib 0.6.2
    Brad Pitcher
    @brad
    Are you guys sure you have valid access tokens? That is one thing that can cause that exception
    Cédric Bonhomme
    @cedricbonhomme
    I'll check with new tokens!
    Cédric Bonhomme
    @cedricbonhomme
    but I was using theses tokens since one week. the first exception said that the token validity expired. Then I was unable to use the refresh token.... Anyway, I'll test again with new tokens.
    Cédric Bonhomme
    @cedricbonhomme
    I have reseted the "client secret". The good news is that I managed to get the access token and refresh token with the script gather_keys_oauth2.py. The last time I used Fitbit API Debug Tool for that. The problem was that the "Callback URL" defined in my application was not "http://127.0.0.1:8080/" as in the gather_keys_oauth2.py script.
    And now, I'll see how to renew the access token with the refresh token with my script.
    Cédric Bonhomme
    @cedricbonhomme
    @brad My new access token just expired and I tried to renew it. Same problem. I even tried with the version of pedrobpio (https://github.com/pedrobpio/demo-python-fitbit/blob/master/demo-2.py#L91) which is supposed to be working. So, this is my code: https://github.com/cedricbonhomme/health/blob/62813f42cb558ee370cc338e72ccd19b31180cbe/refresh_token.py . The commented part is the code I have tested the last week. The error is still the same:
    $ python3.5 refresh_token.py 
    Traceback (most recent call last):
      File "refresh_token.py", line 37, in <module>
        mystring = str(authd_client.client.refresh_token())
      File "/usr/local/lib/python3.5/site-packages/fitbit/api.py", line 163, in refresh_token
        auth=requests.auth.HTTPBasicAuth(self.client_id, self.client_secret)
      File "/usr/local/lib/python3.5/site-packages/requests_oauthlib/oauth2_session.py", line 309, in refresh_token
        self.token = self._client.parse_request_body_response(r.text, scope=self.scope)
      File "/usr/local/lib/python3.5/site-packages/oauthlib/oauth2/rfc6749/clients/base.py", line 409, in parse_request_body_response
        self.token = parse_token_response(body, scope=scope)
      File "/usr/local/lib/python3.5/site-packages/oauthlib/oauth2/rfc6749/parameters.py", line 376, in parse_token_response
        validate_token_parameters(params)
      File "/usr/local/lib/python3.5/site-packages/oauthlib/oauth2/rfc6749/parameters.py", line 386, in validate_token_parameters
        raise MissingTokenError(description="Missing access token parameter.")
    oauthlib.oauth2.rfc6749.errors.MissingTokenError: (missing_token) Missing access token parameter.
    Cédric Bonhomme
    @cedricbonhomme
    but I am able to renew the access token (and get a new refresh token) with the script gather_keys_oauth2.py.
    Aaron Wolen
    @aaronwolen

    I'm in a similar boat: trying to setup a simple script that periodically downloads my data, nothing fancy. Everything works great until the access token expires. As far as I can tell, I've never been able to retrieve a new access token using a refresh token. Like @cedricbonhomme, I have to generate a new access token using gather_keys_oauth2.py.

    Could you layout the intended workflow? Is the fitbit module supposed to automatically refresh the access token when it expires, or should we try to catch token expiration errors and manually call refresh_token()?

    Brad Pitcher
    @brad
    @aaronwolen The refresh is supposed to happen automatically, but it is up to you to save the new access_token and refresh_token for next time. See how we do it with django-fitbit. When a request is complete, we check to see if the access_token it the client is different from what we have on record. That's how we know if the tokens have been refreshed, and we save the updated tokens to the DB. @cedricbonhomme Does that explanation help you?
    Cédric Bonhomme
    @cedricbonhomme
    OK, I see. Thank you! So I do not really have a problem of refreshment. I'll also update the access_token and refresh_token when they change. For the moment I have a simple cli to retrieve and plot (with matplotlib) some data (https://github.com/cedricbonhomme/health).
    Cédric Bonhomme
    @cedricbonhomme
    I had the idea to start working on a simple web app with Flask and to integrate some visualization with d3.js. My plan was to have something not dependent to Fitbit, in order to gather the same kind of data from other services (Garmin, etc.). My db model (draft) was almost ready, until I saw the DB model of django-fitbit ;-) But since I want something abstract from Fitbit, I can't really inspire from this model.
    Raghav Matta
    @ramsamdam
    @cedricbonhomme I am looking to retrieve and save the access token for fitbit by using a callback url from aws lambda or azure functions, but i am unable to retrieve as the access token starts with # and the url gets terminated there itself, is their a work around for that?