dev-master
9999999-dev https://github.com/thesavior/fitbitphpFitbit library with OAuth
Apache-2.0
The Requires
- php >=5.4
- lusitanian/oauth 0.1.*@dev
fitbit
Fitbit library with OAuth
Basic wrapper for OAuth-based FitBit REST API. Seek more information on API developments at dev.fitbit.com. This library does NOT require the OAuth extension to be installed in PHP. This should work on any server with php >= 5.4., (*1)
Library is in BETA as well as the API, so it could still be buggy. We're looking forward to update the library as API moves forward, doing best not to break backward compatibility. That being said, feel free to fork, add features and send pull request to us if you need more awesomness right now, we'll be happy to include them if well done., (*2)
Current notes:, (*3)
searchFoods
and getActivities
are two good example of such endpoints. Nevertheless, this calls should be signed with Authentication header as usual, but access_token parameter is omitted from signature base string. In terms of FitbitPHP, you can make such calls, but you shouldn't use initSession
(so access_token wouldn't be set) and should explicitly set the user to fetch resources from before the call (via setUser
).This package is installable with composer: "thesavior/fitbit": "dev-master", (*4)
First, as always don't forget to register your application at http://dev.fitbit.com and obtain consumer key and secret for your application., (*5)
Library itself handles whole OAuth application authorization workflow for you as well as session tracking between page views. This could be used further to provide 'Sign with Fitbit' like feature (look at next code sample) or just to authorize application to act with FitBit API on user's behalf., (*6)
Example snippet on frontend could look like:, (*7)
<?php $fitbit = new \Fitbit\Api($_SERVER["clientid", "clientsecret"); $fitbit->initSession(); $json = $fitbit->getProfile(); print_r($json);
Note, that unconditional call to 'initSession' in each page will completely hide them from the eyes of unauthorized visitor. Don't be amazed, however, it's not a right way to make area private on your site. On the other hand, you could just track if user already authorized access to FitBit without any additional workflow, if it was not true:, (*8)
if($fitbit->isAuthorized()) <you_are_authorized_user_yes_you_are>
Note. By default, all requests are made to work with resources of authorized user (viewer), however you can use setUser
method to set another user, this would work only for several endpoints, which grant access to resources of other users and only if that user granted permissions to access his data ("Friends" or "Anyone")., (*9)
If you want to fetch data without complete OAuth workflow, only using consumer_key without access_token, you can do that also (check which endpoints are okey with such calls on Fitbit API documentation):, (*10)
require 'fitbitphp.php'; $fitbit = new \Fitbit\Api(FITBIT_KEY, FITBIT_SECRET); $fitbit->setUser('XXXXXX'); $json = $fitbit->getProfile(); print_r($json);
Fitbit library with OAuth
Apache-2.0
fitbit