Download the PHP package brulath/fitbit-php-oauth2 without Composer
On this page you can find all versions of the php package brulath/fitbit-php-oauth2. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download brulath/fitbit-php-oauth2
More information about brulath/fitbit-php-oauth2
Files in brulath/fitbit-php-oauth2
Package fitbit-php-oauth2
Short Description FitBit OAuth 2.0 Client Library based heavily upon djchen/oauth2-fitbit & heyitspavel/fitbitphp
License MIT
Informations about the package fitbit-php-oauth2
Not maintained, archived.
Unofficial Fitbit Client Library for PHP using OAuth2
Wholesale borrows large portions of djchen/OAuth2-Fitbit (minor change to error checking and scope handling) and pavelrisenberg/fitbitphp.
Sets a fitbit-php-oauth2-state cookie during auth flow to prevent CSRF attacks. A session must be started beforehand.
Not guaranteed to work under any circumstances, but it's nice when it does.
Installation
To install, use composer:
Usage
Initialization
All below examples will assume a $fitbit is available. It currently is stateful, so you must set the correct token before using it to make a request.
Token Refreshing Warning
OAuth2 tokens expire; sometimes they expire very quickly. In order to avoid having to manually acquire an updated token from Fitbit, the library does so for you when it detects you attempting to perform an action on an expired token. The good news is that this means you can be lazy regarding keeping tokens fresh, but the less good news is that you need to be vigilant and grab the updated token when it changes.
There are two options for capturing token acquisitions:
Subscribe to a token-change event:
Check post-request for token changes
If you do not wish to use events for some reason, you can check for the token after every call you make to the API:
I'm lazy, so I've made this library automatically refresh oauth details whenever they've expired mid-call. That means after any call the oauth token may have changed, which you will need to check for (and save the new token). I figure it's probably easier to check for changed tokens than catching token expiration exceptions and handling those. Soz brah.
You have two options: checking after every call, or subscribing to events.
Logging
If you want to follow automated events for debugging, grab MonoLog (or other) and pass an instance as 'logger' during initialization.
Authorization
Authorization obtains OAuth2 keys for the Fitbit account in question. You must have a valid client id, client secret, and redirect uri from the Fitbit developer website to use this library. You must specify all of the scopes you wish to use here; you will need to re-authorize the user if you want to expand your scopes later.
Automated Authorization Flow
If you're lazy (hi!) you can have the library redirect the user to the Fitbit website for you.
Manual Authorization Flow
If you're lazy (hi!) you can have the library redirect the user to the Fitbit website for you.
Authorization involves sending the user to Fitbit's website with a 'state' code so we can verify the request came from us. Store the state and send the user off to the uri.
When the user returns to the redirect_uri specified on the Fitbit developer website, there will be a query ($_GET) parameter set with the state we stored above; check they match to ensure the request originated with us.
Restoring access
Making a request
Inspect the FitbitPHPOAuth2 class to find the appropriate method. In this case, I want all activities on a date:
License
The MIT License (MIT).