demo-git/fitbit

There is no license information available for the latest version (1.1) of this package.

Fitbit REST API library

1.1 2016-12-01 18:07 UTC

This package is not auto-updated.

Last update: 2024-09-23 15:05:22 UTC


README

Very basic Fitbit API. There are working Oauth 2 and few Fitbit endpoints.

Examples

First you have to generate login url.

$fitbit = new Fitbit('Client ID', 'Client (Consumer) Secret');
echo $fitbit->getLoginUrl('http://yourcallbackurl.cz', ['profile']);

User is redirected to your callback url with code in paramters. Get this code and request token from fitbit.

$token = $fitbit->getToken('CODE', 'http://yourcallbackurl.cz');
$fitbit->setToken($token);

Token have only 1 hour duration and you have to use refresh token endpoint

if ($_SESSION['fitbit']->dateExpire <= time()) {
    $_SESSION['fitbit'] = $fitbit->refreshToken($_SESSION['fitbit']);
    $_SESSION['fitbit']->dateExpire = (time() - 60) + $_SESSION['fitbit']->expires_in;
}

After you have token, you can use Fitbit endpoints.

print_r($fitbit->profile->get());

$fitbit->sleep->log(new \DateTime("2016-03-10 10:24"), 8 *60 * 60 * 1000);

print_r($fitbit->water->get(new \DateTime("2016-03-10")));