dev-master
9999999-dev https://github.com/popthestack/fitbitphpFitbit library with OAuth.
Apache-2.0
The Requires
- php >=5.3.0
- lusitanian/oauth ~0.2
by Eli White
fitbit
Fitbit library with OAuth.
Basic wrapper for the OAuth-based FitBit REST API. See dev.fitbit.com for details on their OAuth implementation., (*1)
Both this library and the Fitbit API are in beta., (*2)
This library does not require the PHP OAuth extension. It should work on any server with PHP >= 5.3., (*3)
This package is installable with composer: "popthestack/fitbit": "dev-master", (*4)
You need a consumer key and secret. You can obtain them by registering an application at http://dev.fitbit.com., (*5)
Simple, but full OAuth workflow example:, (*6)
$factory = new \Fitbit\ApiGatewayFactory; $factory->setCallbackURL($callback_url); $factory->setCredentials($consumer_key, $consumer_secret); $adapter = new \OAuth\Common\Storage\Session(); $factory->setStorageAdapter($adapter); $auth_gateway = $factory->getAuthenticationGateway(); if (isset($_GET['oauth_token']) && isset($_GET['oauth_verifier'])) { $auth_gateway->authenticateUser($_GET['oauth_token'], $_GET['oauth_verifier']); } elseif (isset($_GET['connect'])) { $auth_gateway->initiateLogin(); } if ($auth_gateway->isAuthorized()) { $user_gateway = $factory->getUserGateway(); $user_profile = $user_gateway->getProfile(); echo ''; print_r($user_profile); echo ''; } else { echo 'Not connected.'; }
If you want to retrieve the OAuth token and secret from the session to store elsewhere (e.g. a database):, (*7)
$storage = $factory->getStorageAdapter(); $token = $storage->retrieveAccessToken('FitBit'); // Save these somewhere: $oauth_token = $token->getRequestToken(); $oauth_secret = $token->getRequestTokenSecret();
Here's how to use your OAuth token and secret without the Session
storage adapter.
It's a little cumbersome, but it works. If I ever have time for it, I'd like to
replace the current OAuth library with something that doesn't enforce so much... stuff., (*8)
$token = new \OAuth\OAuth1\Token\StdOAuth1Token(); $token->setRequestToken($oauth_token); $token->setRequestTokenSecret($oauth_secret); $token->setAccessToken($oauth_token); $token->setAccessTokenSecret($oauth_secret); $adapter = new \OAuth\Common\Storage\Memory(); $adapter->storeAccessToken('FitBit', $token); $factory->setStorageAdapter($adapter); $user_gateway = $factory->getUserGateway(); $food_gateway = $factory->getFoodGateway(); $user_profile = $user_gateway->getProfile(); $user_devices = $user_gateway->getDevices(); $foods = $food_gateway->searchFoods('banana split'); echo ''; print_r($user_profile); print_r($user_devices); print_r($foods); echo '';
setUserID
method available on ApiGatewayFactory
and the Endpoint Gateways (e.g. UserGateway
, FoodGateway
).Fitbit library with OAuth.
Apache-2.0
fitbit