05-14-2015 10:32
05-14-2015 10:32
Hi,
I have an existing application that manages user' devices and subcriptions using oauth1. I am currently storing oauth1 tokens in my database. I would like to start moving some of the users to oauth2 but would like to revision my app once I start satisfied with the migration.
So is it possible to call the fitbit api for the same user using both authentication methods concurrently?
Or is it that once I migrate a given user to oauth2, the oauth1 authentication for this user would be disabled?
Also I am working on a service that would collect various metrics for my user base. This service would receive push notifications from fitbit and then subsequently query the api and gather activity details using an oauth2 token authentication for that user. I have registered a push api url in my fitbit application with a default subscriber. Once I get a notification I need to associate the notification with my user id in order to looking their oauth2 tokens. I am a bit confused with the default subscriber id and the add subscription api subcription id. My understanding would be to add subcriptions using for subcription id the user ID for my application's users. What I would like to do is to add subscription for each of my users to I can lookup the oauth2 token in the callback using my application user ID. It seems that adding multiple subscription IDs using the same subscribe ID yield to conficts. Again a bit confused by the docs, so what is the best way to achieve this scenario.
Thanks!
05-14-2015 10:49 - edited 05-14-2015 10:56
05-14-2015 10:49 - edited 05-14-2015 10:56
1) Yes you can use both Oauth 1.0a and 2 simultaneously.
2) You can have just one subscription endpoint and add all users to this subscription.
When fitbit will be sending you push notifications the body of message will contain user id whose data had been chaned.
to add subscription just user https://api.fitbit.com/1/user/-/apiSubscriptions/<subscriptionIdNameThatYouChoose>.json
If you have several subscription endpoints when creating subscription to user the push notifications will automatically pick default subscription endpoint, unless you specify which endpoint to use via X-Fitbit-Subscriber-Id header.
05-14-2015 11:01
05-14-2015 11:01
Hi Ivan,
Thanks for the prompt reply. On the subscription api it seems that I get a 409 by adding additional subscription_id using my default subscriber id. I'll double check my code to make sure this is not a pilot error. Does it sound that this would work or am I missing something?
Thanks!!
05-14-2015 11:14
05-14-2015 11:14
FYI I've confirmed the 409.
I am issuing the following calls:
1/user/-/apiSubscriptions/100.json => 201
1/user/-/apiSubscriptions/101.json => 409
So any attempt to add additional push notification seems to fail. What am I missing?
Thanks!
05-14-2015 11:21
05-14-2015 11:21
You can not create more then one subscription with the same id.
in your case 101 is id of subscription.
I bet if you do: GET http://api.fitbit.com/1/user/-/apiSubscriptions.json you'll get list of subscriptions you have and one of them will have id "101".
05-14-2015 11:32
05-14-2015 11:32
Hum I am confused then.
I am specifying different subscription ids and using the default subscriber id. Is that wrong?
Here is my sequence:
1/user/-/apiSubscriptions/100.json => 201
1/user/-/apiSubscriptions => 200
{
"apiSubscriptions": [
{
"subscriberId": "1",
"ownerId": "XXX",
"ownerType": "user",
"collectionType": "user",
"subscriptionId": "100"
}
]
}
1/user/-/apiSubscriptions/101.json => 409
Would assume that if this call succeeded I would now have the following entries.
{
"apiSubscriptions": [
{
"subscriberId": "1",
"ownerId": "2BH3WL",
"ownerType": "user",
"collectionType": "user",
"subscriptionId": "100"
},
{
"subscriberId": "1",
"ownerId": "XXX",
"ownerType": "user",
"collectionType": "user",
"subscriptionId": "101"
}
]
}
I would assume based on your initial comment that the second add subscription with a different subscription id would succeed. Hence creating new subscriptions for each of my users. Hence in the push notification I can pull the subscriptionID to now which user to fetch the metrics for.
Is this an incorrect assumption? If so how should I procceed?
Tx!
05-14-2015 11:34
05-14-2015 11:34
In your case you're trying to add subscription to the same user twice. You can not do this as well.
Please read precisely https://wiki.fitbit.com/display/API/Fitbit+Subscriptions+API
it will take time to understand it. But you really need to read it very carefuly to fully understand how is Fitbit subscriptions api works.
05-14-2015 12:00
05-14-2015 12:00
I see where I went wrong no user id hence uses the authenticated user.
Ok - that's great - So next question is how do I retrieve the fitbit user id?
In oauth1 the user id was returned as part of the auth.
So how does one get the FB user id in the oauth2 case, fetching profile info does not seem to return the currently authenticated user?
Tx!
05-14-2015 12:01 - last edited on 05-14-2015 12:49 by JeremiahFitbit
05-14-2015 12:01 - last edited on 05-14-2015 12:49 by JeremiahFitbit
Did you try?
What api endpoint do you use to fetch user profile?