Fitbit Subscription API

I have successfully integrated the Fitbit api on my website using the Fitbit PHP library (www.disciplinexgames.com/fitbit). It works fine, but now I want to use the subscription API so that we can update the data in the database as soon as new data appears. I went through the Subscription API Docs and registered the application with the subscriber endpoint, but when it comes to receiving update notifications, I'm lost. Actually did not get much help from the documents in terms of what I should add or change in my code, etc. Is there any sample code for PHP related to the subscription API, or suggestions on what I should do.

Working URL: http://www.disciplinexgames.com/fitbit/

Any help would be really appreciated. This is a bit frustrating as I am not getting any errors, but at the same time not getting updates.

thank

+5
source share
1 answer

Sorry for this answer coming two years later, but maybe this will help someone.

Once you know the user's secret token and token, you can subscribe to your channel using the following OAUTH POST request. This URL is for an activity feed.

<?php
$consumerKey = "lajsdf23l4l8asdfn238ladf8xjk92oi"; //From Fitbit website when you sign up for an app
$consumerSecret = "l8adl3halsdf82p9adfads2gjadsf"; //From Fitbit website when you sign up for an app
$oauth = new OAuth($consumerKey,$consumerSecret,OAUTH_SIG_METHOD_HMACSHA1,OAUTH_AUTH_TYPE_AUTHORIZATION);

$usersToken = "k28a9wifvnc89w2o8oigaad8e23r23jf";
$usersSecret = "234o8fdofsy8df89aydfoyo84e2902af";
$oauth->setToken($usersToken,$usersSecret);

$subscriptionURL = "https://api.fitbit.com/1/user/-/activities/apiSubscriptions.json";

try{
    //Send a POST to subscribe as stated on https://wiki.fitbit.com/display/API/Fitbit+Subscriptions+API
    $oauth->fetch($subscriptionURL, null, OAUTH_HTTP_METHOD_POST); 
    print_r(json_decode($oauth->getLastResponse())); // Make sure the request was successful 
}
catch(Exception $e){
    echo 'ERROR:';
    print_r($e);
    print_r($oauth->getRequestHeader('POST', $url));
}

Your subscriber's endpoint should be a web page where you have a code that can receive Fitbit data and do whatever you need. Below is the PHP code to get you started.

<?php   
// Get the input data and create a PHP object to use.
$fitbitPushData = file_get_contents("php://input");
$fitbitData = json_decode($fitbitPushData);

RequestBin http://requestb.in/ URL . , , Fitbit, - . JSON URL- , , URL .

, :

URL- . URL- , Fitbit, . Fitbit URL- , 10% , 3 .

, . , . API . 150 API , . , , Fitbit, , .

+2

All Articles