Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Help me connect to the API (Swift)

Hey, i'm quite new with using web api
Recently i created an app to see user's step, and heartrate data 
but when i after the user login to give permission the link doesn't redirect me to the permission page
instead it redirect me to this

the error i got

 

this is the link i use

https://www.fitbit.com/oauth2/authorize?response_type=token&client_id=22BK83&redirect_uri=InTouch%3A...

 

please help me

 

Best Answer
0 Votes
7 REPLIES 7

S__5079047.jpg

this is the error i got  

Best Answer
0 Votes

Hi @AxelSidharta 

 

Welcome to the forums!

 

When attempting to go through your authorization process, I am seeing the following error:

 

Developer information: invalid_request - Invalid redirect_uri parameter value

 

Please see our common solution for troubleshooting a redirect URI here.

 

Hope this helps. Let me know if you have any additional questions.

Best Answer
0 Votes

hi john

 

i got trough this problem and i got another one

after i got the token 

i don't know how to make the request 
i want to get step data from the user 

using this one

GET https://api.fitbit.com/1/user/-/activities/steps/date/today/1m.json

i don't know where the token is used on
i tried this

GET https://api.fitbit.com/1/user/-/profile.json
Authorization: Bearer eyJhbGciOiJIUzI1NiJ9.eyJleHAiOjE0MzAzNDM3MzUsInNjb3BlcyI6Indwcm8gd2xvYyB3bnV0IHdzbGUgd3NldCB3aHIgd3dlaSB3YWN0IHdzb2MiLCJzdWIiOiJBQkNERUYiLCJhdWQiOiJJSktMTU4iLCJpc3MiOiJGaXRiaXQiLCJ0eXAiOiJhY2Nlc3NfdG9rZW4iLCJpYXQiOjE0MzAzNDAxMzV9.z0VHrIEzjsBnjiNMBey6wtu26yHTnSWz_qlqoEpUlpc

but the token i get is much shorter than this one

sorry i'm really new with using API 

Best Answer
0 Votes

@AxelSidharta Can you please PM me the access token you are receiving? Also, please let me know which authorization flow you are using (authorization or implicit).

Best Answer
0 Votes

@AxelSidharta Thanks for sending me the token you are receiving. What you've sent me in PM appears to be a refresh token, not an access token. You need to enter the access_token, not the refresh_token, into your authorization header when making an API call. 

 

After the user authenticates your application with the authorization code grant flow, you will receive an access token and a refresh token. You need to use the access token to make requests to the Fitbit API. The refresh tokens are used to obtain a new access token when they expire.

 

The response you receive during the access token request should look like this:

{
    "access_token": "eyJhbGciOiJIUzI1NiJ9.eyJleHAiOjE0MzAzNDM3MzUsInNjb3BlcyI6Indwcm8gd2xvYyB3bnV0IHdzbGUgd3NldCB3aHIgd3dlaSB3YWN0IHdzb2MiLCJzdWIiOiJBQkNERUYiLCJhdWQiOiJJSktMTU4iLCJpc3MiOiJGaXRiaXQiLCJ0eXAiOiJhY2Nlc3NfdG9rZW4iLCJpYXQiOjE0MzAzNDAxMzV9.z0VHrIEzjsBnjiNMBey6wtu26yHTnSWz_qlqoEpUlpc",
    "expires_in": 3600,
    "refresh_token": "c643a63c072f0f05478e9d18b991db80ef6061e4f8e6c822d83fed53e5fafdd7",
    "token_type": "Bearer",
    "user_id": "26FWFL"
}

I hope this clarifies any confusion. Please let me know if you have any additional questions.

Best Answer
0 Votes

@JohnFitbit 
i now used the access token but now i got this error 

Authorization Error: Invalid authorization token type

how do i get step data after i got the access token 
sorry for bothering john

Best Answer
0 Votes

@AxelSidharta No worries! That's why I'm here.

 

I think I was able to reproduce the error you are seeing. Can you verify if this is the same error you saw?

 

{"errors":[{"errorType":"system","fieldName":"n/a","message":"Authorization Error: Invalid authorization token type"}],"success":false}

 

I remember seeing this error for a different user and it was due to them not including "Bearer" in their authorization header. Please make sure you are including this in your request.

 

Your request should look like this:

GET https://api.fitbit.com/1/user/-/profile.json
Authorization: Bearer eyJhbGciOiJIUzI1NiJ9.eyJleHAiOjE0MzAzNDM3MzUsInNjb3BlcyI6Indwcm8gd2xvYyB3bnV0IHdzbGUgd3NldCB3aHIgd3dlaSB3YWN0IHdzb2MiLCJzdWIiOiJBQkNERUYiLCJhdWQiOiJJSktMTU4iLCJpc3MiOiJGaXRiaXQiLCJ0eXAiOiJhY2Nlc3NfdG9rZW4iLCJpYXQiOjE0MzAzNDAxMzV9.z0VHrIEzjsBnjiNMBey6wtu26yHTnSWz_qlqoEpUlpc

Let me know if this helps!

Best Answer
0 Votes