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

Unable to authenticate in objective c

ANSWERED

I have integrated Fitbit into my app .App development is done using Objective c

for login i am getting authentication error as 

invalid_request - Invalid redirect_uri parameter value

Redirect url which i have used is 

https://www.fitbit.com/oauth2/authorize?response_type=code&client_id=22DFL2&redirect_uri=http://52.1...

 

what is the url which we have to give  Redirect url

Please give  solution

Best Answer
0 Votes
1 BEST ANSWER

Accepted Solutions

i am getting the error as safari cannot open the page because the server cannot be found .But i see this in safari i am getting the code in url but open url is not triggering in app.

My redirect url is https://samplebit://callback

and in scheme url i am giving as samplebit://

i need solution to the above problem

 

View best answer in original post

Best Answer
0 Votes
19 REPLIES 19

Hi @kshilpa. I’ve moved your post to the development app. Hopefully someone can help you here. 

 

Best Answer
0 Votes

Hi @kshilpa,

 

Have you confirmed the redirect URL entered in your dev.fitbit.com application configuration is the same as the redirect URL provided in the /oauth2/authorize endpoint?   If they are different, you can receive that error message.

 

Gordon

Gordon Crenshaw
Senior Technical Solutions Consultant
Fitbit Partner Engineering & Web API Support | Google
Best Answer
0 Votes

i have registered my app in fitbit and i got client id ,secret key ,redirect url as goiven below

OAuth 2.0 Client ID

22DFL2

 

Client Secret

22db8fc2967f6a077aeeba4c8ed20037

 

Callback URL

https://secureone.anvayaa.com/testAnvayaaARS

 

when i login with my credentials its redirecting to the above url in the app but we are not getting any authentication code neither hitting open url in app-delegate  .i have also given url scheme  as redirect url .

 

may i know what is the exact problem ,Please help me. i am struck in this problem from many days

Best Answer
0 Votes

how to provide redirect url in /oauth2/authorize endpoint .can you explain it.

i have tried in OAuth 2.0 tutorial page  but  before when i clicked the link i got the code and token also ,but later on i did  not get the code i am getting as 

https://www.fitbit.com/oauth2/authorize?response_type=code&client_id=22D9RY&redirect_uri=samplebit%3...

Sorry, that page is following a different trail.

 

can you explain the problem please

Best Answer
0 Votes

Hi @kshilpa,

 

In the most recent /oauth2/authorize statement you provided, I see your redirect_uri is set to redirect_uri=samplebit://.  The redirect_uri needs to be an absolute URL.  Would you please change it to something like redirect_uri=samplebit://callback.

 

 

Gordon Crenshaw
Senior Technical Solutions Consultant
Fitbit Partner Engineering & Web API Support | Google
Best Answer
0 Votes

Hi thanks for reply

but tried doing in web adding  some part to url  its working fine in oAuth2.tutorial page but its not working in app ,code is coming but open url is not triggering. i think problem is with scheme url .

this is my  callback url https://samplebit://callback callback url .

what should be the url scheme ?

i have given as samplebit://callback in my app .Its not working please give reply as soon as possible

 

Best Answer
0 Votes

i am getting the error as safari cannot open the page because the server cannot be found .But i see this in safari i am getting the code in url but open url is not triggering in app.

My redirect url is https://samplebit://callback

and in scheme url i am giving as samplebit://

i need solution to the above problem

 

Best Answer
0 Votes

Hi,

How to verify the subscriber?

i have used this url  to verify a subscriber

GET https://yourapp.com/fitbit/webhook?verify=correctVerificationCode
https://samplebit.com/fitbit/webhook?verify=b5cd78e0342331260800cd18f192ff111e68eaedc5c35c30bedf62e091a80a6

but you are not successfully subscribed is coming

what is the process 

Best Answer
0 Votes

Hi @kshilpa

 

I'm sorry for my earlier typo.   My example redirect_uri should have been https://samplebit/callback.  This URL needs to be an entry point back into your application that would parse the URL and grab the authorization code embedded in the URL.   If https://samplebit/callback doesn't exist in your application, then the page should fail.

Gordon Crenshaw
Senior Technical Solutions Consultant
Fitbit Partner Engineering & Web API Support | Google
Best Answer
0 Votes

First, have you verified the subscriber endpoint, https://yourapp/fitbit/webhook, is accessible to the outside world?  If so, when you press the "Verify" button in dev.fitbit.com, Fitbit will send your subscriber endpoint 2 GET requests.  The first GET request will contain your verification code. Your application needs to reply with a 204 response.  The second GET request will contain an intentional invalid code. Your application needs to reply with a 404 response.

Gordon Crenshaw
Senior Technical Solutions Consultant
Fitbit Partner Engineering & Web API Support | Google
Best Answer
0 Votes
Subscriber ID Verified at / Verification code Stats
Subscriber has not been successfully verified. Verification code: 
No Stats Available

 

i have clicked verify but no status available  is coming.

Can you explain what should we do and what is the problem.

Best Answer
0 Votes

When you press the "Verify" button, Fitbit is going to send 2 GET requests to your subscriber endpoint

 

GET https://secureone.anvayaa.com/testAnvayaaARS?verify=<CorrectVerificationCode>

The verification code can be found under the "Verify" button.  Your application should to confirm the verification code is correct and respond to Fitbit with a 204

 

GET https://secureone.anvayaa.com/testAnvayaaARS?verify=<IncorrectVerificationCode>

Fitbit will intentional send an incorrect verification code.  Your application should confirm the verification code is incorrect and response to Fitbit with a 404

 

Is your application doing this?

 

Gordon Crenshaw
Senior Technical Solutions Consultant
Fitbit Partner Engineering & Web API Support | Google
Best Answer
0 Votes

Subscriber ID Verified at / Verification code Stats

2019-02-12T09:16:13.719Z
No Stats Available

 

subscriber is verified but no stats are availbale is shown.Means when subscriber logins in Fitbit from app than only endpoint url will be triggered?how will be the data format of steps changed ,heart rate etc.if many  subcribers login  end point url is same than how can the data be managed for each subscriber.

Best Answer
0 Votes

Fantastic!!  The next step is to create a subscription for one of the users that have authorized access to your application.  Here's the link to the docs: https://dev.fitbit.com/build/reference/web-api/subscriptions/#adding-a-subscription.  

 

An example of what this might look like for subscribing to the activities collection is

 

POST https://api.fitbit.com/1/user/-/activities/apiSubscriptions/320json

specifying the header X-Fitbit-Subscriber-Id set to the value of your subscriber Id (e.g. 1).

 

After the subscription has been created, when your user updates their activities data, your application should receive a webhook notification.  The subscriber stats value should increase.

Gordon Crenshaw
Senior Technical Solutions Consultant
Fitbit Partner Engineering & Web API Support | Google
Best Answer
0 Votes

 

I have given https://api.fitbit.com/1/user/-/activities/apiSubscriptions/AKCSS1.json post but i am gettig the reply as

given Header  X-Fitbit-Subscriber-Id:AKCSS1

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

 

what is the problem in the above process  .should  we send token in the  above url

Best Answer
0 Votes

Yes, you still need to provide the Authorization header and provider a Bearer token (access token)

Gordon Crenshaw
Senior Technical Solutions Consultant
Fitbit Partner Engineering & Web API Support | Google
Best Answer
0 Votes

can you tell me clearly what we should send in header and body, i am sending subscriber id and token in header.

 

what are the exact keys?

 

Best Answer
0 Votes

 I have tried this  url https://api.fitbit.com/1/user/4LTZBZ/activites/apiSubscriptions/AKCSS1.json

[{"key":"access_token","value":"eyJhbGciOiJIUzI1NiJ9.eyJhdWQiOiIyMkQ5UlkiLCJzdWIiOiI3N0JSUEgiLCJpc3MiOiJGaXRiaXQiLCJ0eXAiOiJhY2Nlc3NfdG9rZW4iLCJzY29wZXMiOiJyc29jIHJzZXQgcmFjdCBybG9jIHJ3ZWkgcmhyIHJudXQgcnBybyByc2xlIiwiZXhwIjoxNTUwMTUzOTkwLCJpYXQiOjE1NTAxMjUxOTB9.jO6kx3x67z-MQktXOkWwQ6rkWpmrxpDaAGcd0_efLng","description":""},{"key":"Authorization","value":"Basic c2hpbHBhLmtAeHJnY29uc3VsdGluZy5jb206aHlkZXJhYmFk","description":""},{"key":"Content-Type","value":"application/json","description":""}]

Response:

{"success":false,"errors":[{"errorType":"invalid_client","message":"Invalid authorization header. Client id invalid. Visit https://dev.fitbit.com/docs/oauth2 for more information on the Fitbit Web API authorization process."}]}

 

but it is showing invalid client id  .authorisation it is taking automatically when given credentials of fitbit account.what is the problem.

the document is not at all engough  to get successfull data

Best Answer
0 Votes

It's probably not a good idea to provide your tokens in the public forum.  You can private message those to me.

 

The syntax for adding a subscription should look similar to this

https://api.fitibt.com/1/user/<user-id>/activities/apiSubscription/<subscription-id>.json

 

And you'll need these headers

Authorization = Bearer <the user-id's access token>

X-Fitbit-Subscriber-Id = <subscriber-id>    [NOTE: Only needed if you have multiple subscribers.  Otherwise, we will use the default one]

 

 

 

Gordon Crenshaw
Senior Technical Solutions Consultant
Fitbit Partner Engineering & Web API Support | Google
Best Answer
0 Votes