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

Call API after receiving update Notifications

ANSWERED

I'm working on an application that aggregate data from a group of user.

I've already done the authorization for the users and the subcription of each user to the subscriber of my app.

The subscriber works fine, in fact i receive the update notification everytime a user sync his data.

My question is:

How i have to do to make request to the API to get the new activity with the only X-Fitbit-Signature that i receive in update notification header ?

 

I'm working on wordpress, so PHP

 

Thanks

 

Best Answer
0 Votes
1 BEST ANSWER

Accepted Solutions

The subscriptions notification is a POST request to your subscriber. Look at the JSON in the request body and you'll see the user id, the name of the subscription, the date, and the resource collection that changed. In your app, lookup the OAuth 2 access token for that user id and make API requests as you normally do.

 

The X-Fitbit-Signature header is what allows your subscriber to know the request is authentic from Fitbit.

View best answer in original post

Best Answer
4 REPLIES 4

The subscriptions notification is a POST request to your subscriber. Look at the JSON in the request body and you'll see the user id, the name of the subscription, the date, and the resource collection that changed. In your app, lookup the OAuth 2 access token for that user id and make API requests as you normally do.

 

The X-Fitbit-Signature header is what allows your subscriber to know the request is authentic from Fitbit.

Best Answer

Thanks Jeremiah, i wasn't sure that I have to collect the auth token of the all the users.

I tried with cocoa rest client to call the API url build with the parameters received and the user acces token and works fine.

In php i'm trying via cURL but i receive only 1 fro response and not the json.

 

Here it is my code:

  $headr = array();
  $headr[] = 'Authorization: Bearer '.$accesstoken;

$crl = curl_init();
curl_setopt($crl, CURLOPT_URL, $APIurl); curl_setopt($crl, CURLOPT_HTTPHEADER,$headr); curl_setopt($crl, CURLOPT_POST,false); $rest = curl_exec($crl); if ($rest === false) { // throw new Exception('Curl error: ' . curl_error($crl)); $rest = 'Curl error: ' . curl_error($crl); }

 

Best Answer
0 Votes

Nevermind, I already resolved.

I had to add this line to have response body 

 

curl_setopt($crl, CURLOPT_RETURNTRANSFER, 1);

 

Thanks for helping me ! 

Best Answer
0 Votes

@JeremiahFitbit How do I make a call to the API in order to fetch the user's activity changes with only X-Fitbit_signature that i received in header. I am trying to automate the process so that anytime any notification comes i can fetch the user activity data. I am using oauth 2.0 and i cannot create access token for fitbit as it needs to have a authorization code which comes after redirection from the fitbit. Kindly help. I have asked at Twitter support, emailed and looked at many places but i can not find a solution. This is very important. Kindly help. 

Best Answer
0 Votes