oauth2-fitbit
oauth2-fitbit copied to clipboard
Server script to pull fitbit datat daily.
trafficstars
I am trying to run this in a server script. Far as I know I can do the auth stuff in the browser to get the auth code, then plug it into another script and it should work? But I get invalid auth code? Any advice? Thanks
./import.php
invalid_grant - Authorization code invalid: xxxxxxxx Visit https://dev.fitbit.com/docs/oauth2 for more information on the Fitbit Web API authorization process.
solved it here is the code, need to build my own token
<?php
require __DIR__ . '/vendor/autoload.php';
use djchen\OAuth2\Client\Provider\Fitbit;
use League\OAuth2\Client\Token\AccessToken;
$provider = new Fitbit([
'clientId' => 'xxxxx',
'clientSecret' => 'xxxxx',
'redirectUri' => 'xxxxxxx'
]);
$existingAccessToken = new AccessToken([
'access_token' => 'xxxxxx',
'refresh_token' => 'xxxxx',
'expires' => 1630589048
]);
if ($existingAccessToken->hasExpired()) {
$newAccessToken = $provider->getAccessToken('refresh_token', [
'refresh_token' => $existingAccessToken->getRefreshToken()
]);
}
$request = $provider->getAuthenticatedRequest(
Fitbit::METHOD_GET,
Fitbit::BASE_FITBIT_API_URL . '/1/user/-/foods/log/water/date/2021-07-01/2021-07-30.json',
$existingAccessToken,
['headers' => [Fitbit::HEADER_ACCEPT_LANG => 'en_GB'], [Fitbit::HEADER_ACCEPT_LOCALE => 'en_US']]
);
$response = $provider->getParsedResponse($request);
print '<pre>';
print_r($response);
I copied the access token and refresh token i got when I did the browser based auth.
refresh token not working says invalid refresh token working on a fix for this