Search code examples
iospostmanfitbit

Invalid Access Token in FitBit


i'm trying to integrate the Fitbit SDK in my iOS app. I have created project on fitbit now i'm running there API in Postman to check profile, but in response it is showing me invalid access token,

{
"errors": [
    {
        "errorType": "invalid_token",
        "message": "Access token invalid: 39ec7defa6f0e33b314bbf6217279b15. Visit https://dev.fitbit.com/docs/oauth2 for more information on the Fitbit Web API authorization process."
    }
],
"success": false

} This is my API https://api.fitbit.com/1/user/-/profile.json and this is what i'm passing in header, Authorization : Bearer Client Secret But it is showing me status code 401 having error of invalid access token . How can i get the access token for my app?


Solution

  • You need to get an OAuth2.0 token from the FitBit authentication service before you can call any other endpoints on the API. You will need to redirect your app to Safari and go to the fitbit authentication service so that the user can log in and authorise your apps access to their FitBit data. The callback will then return an OAuth token that you can pass in subsequent requests.

    You will need to call something like this:

    https://www.fitbit.com/oauth2/authorize?response_type=code&client_id=%@&scope=%@&redirect_uri=%@"
    

    This is the official fitbit documentation for Authorisation:

    https://dev.fitbit.com/build/reference/web-api/oauth2/