09-09-2019 04:28
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

09-09-2019 04:28
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Receiving accesstoken and refreshtoken <oauth> component in settings OnAccessToken. One of the api call is returning 401 because access token expired. How to invoke the refresh token call??? or any internal things happen in the fitbit??.. No examples found in the documentation. Please provide code snippet to retain the user state???.. There is no much documentation or examples on refresh token.
function getDataFromResourceServer() {
console.log('hello')
fetch(endpoint, {
method: 'GET',
headers:{
'Content-Type': 'application/json',
'Authorization': 'bearer ' +settingsStorage.getItem('token')
}} )
.then(function (response) {
// Here getting 401 response
console.log('response', JSON.stringify(response));
response.json()
.then(function(data) {
console.log('success ', data);
});
})
.catch(function (err) {
console.log("Error fetching : " + err);
});
}
09-10-2019 07:01
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post



09-10-2019 07:01
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Hi @Sandy111
Please review this section of the documentation for refreshing access tokens: https://dev.fitbit.com/build/reference/web-api/oauth2/#refreshing-tokens. The syntax is
POST https://api.fitbit.com/oauth2/token
Authorization: Basic Y2xpZW50X2lkOmNsaWVudCBzZWNyZXQ=
Content-Type: application/x-www-form-urlencoded
grant_type=refresh_token&refresh_token=abcdef01234567890abcdef01234567890abcdef01234567890abcdef0123456
Best,
Gordon
Senior Technical Solutions Consultant
Fitbit Partner Engineering & Web API Support | Google

09-11-2019 05:01 - edited 09-13-2019 00:24
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

09-11-2019 05:01 - edited 09-13-2019 00:24
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
- Who Voted for this post?
I am building an app in fitbit watch. Under settings section below is my code snippet. From companion we are making api calls using fetch, access token is getting expired because it is short lived. Now how to call the token endpoint with the refresh token and get access token??
where should i call this??.. Should i call the oauth component or how??
<Oauth
settingsKey="oAuth1"
title= "Login"
label={label}
status={status}
authorizeUrl="https://blahblah.com/Authorize"
requestTokenUrl="https://blahblah.com/OAuth/Token"
clientId="watchdev"
clientSecret="watchXXXX"
scope="All"
onAccessToken={async (data) => {
console.log('heloooooooooooooooooooooo');
console.log(JSON.stringify(data));
label = "You are logged in as " + props.settingsStorage.getItem('userName');
}}
/>
09-17-2019 06:03
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

09-17-2019 06:03
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Does anyone help??

09-25-2019 13:52
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post



09-25-2019 13:52
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
HI @Sandy111
After you determine the access token has expired, you should execute the endpoint as I described in the previous post by providing your current refresh token to obtain a new access token and refresh token.
In your syntax, it looks like you're trying to use OAuth version 1. This is not supported. You should be using OAuth 2.0. Please review the documentation for more details: https://dev.fitbit.com/build/reference/web-api/oauth2/. If you would like to test the OAuth 2.0 flow and the refresh token flow, you can do so with the OAuth 2.0 tutorial: https://dev.fitbit.com/build/reference/web-api/troubleshooting-guide/debugging-tools/#oauth-2-0-tuto...
Senior Technical Solutions Consultant
Fitbit Partner Engineering & Web API Support | Google

