Sell wearable-devices-producing data on the Streamr marketplace

Gang Liu
Gang Liu
Oct 14, 2018 · 6 min read

With the development of Internet of Things (IoT), various wearable devices are produced to measure personal heart rate, steps climbed, and other useful fitness data¹. However, the data is in the control of the manufacturer and sold in the offline market without our permission². Therefore, Streamr aims to create a global decentralized data exchange platform to help you own yourself data.

Their explainer video is here:

In this tutorial, you will learn how to access your Fitbit fitness data, and sell it on the Streamr marketplace. The Fitbit is an American company headquartered in San Francisco, California. Its products are activity trackers, wireless-enabled wearable technology devices.

Step 1: Register an app on

First you need to register an account on, and then click MANAGE YOUR APPS on the top right area. Next you need to click Register a new app button at the top right area to start with.

After you click the red Register button, you will be able to see the credentials for the app you just registered. The OAuth 2.0 Client ID and Client Secret will be used in the next step.

Step 2: Use the OAuth 2.0 tutorial page

Next you need to right click the OAuth 2.0 tutorial page link and open it in a new tab, so that you can look back at your app’s credentials easily. Make sure the Implicit Grant Flow is chosen instead of Authorization Code Flow— this will make things much easier! After you copy/paste the Client ID and Client Secret into the blanks and put in the Redirect URI, click the auto-generated link.

Then you will see the confirmation page. Just click Allow.

And you will be led to the ‘Redirect URI’, which is ‘’ in this case. But the address bar now shows a very long string which is the token for your app.

Next you need to copy and paste everything in the address bar but without the starting part ( ) to the Parse response section, and hit enter key once. This way you can clearly see what the token is, what the scope is, and how long the token is valid.

Step 3: Make request and get the data!

After you are done with the Parse response, the next step is ready for you. You need to create a Streamr stream at first. Then please copy the following code to your host, replace the $YOUR_LOGFILE_PATH, $YOUR_STREAM_ID, $YOUR_API_KEY, $YOUR_CLIENT_BASH64, $YOUR_ACCESS_TOKEN, $YOUR_REFERSH_TOKEN with yours, and keep running the script for live data to appear in a stream. Note that, this particular script has been coded in python 2.7. If you use python 3.x or other script languages, you will need to re-code it first.

# -*- coding: utf-8 -*-import requests
 import json
 import logging as LOG
 import hashlib
 import time
 import threading as thdLOG.basicConfig(level=LOG.DEBUG,
 format=’%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s’,
 datefmt=’%a, %d %b %Y %H:%M:%S’,
 filemode=’a’)# global variable# Get the following infomation from the Streamr
 API_KEY = ‘$YOUR_API_KEY’# Get the following information from the Google Fitness Platform
 REFRESH_TOKEN = ‘$YOUR_REFERSH_TOKEN’def get_user_token():
 “”” Request Fitbit Access token using the refresh token
 NOTE: Update every 45min
 global CLIENT_BASH64
 url = ‘’
 body = “grant_type=refresh_token&refresh_token=%s”%(REFRESH_TOKEN)
 paras = {‘Authorization’: “Basic %s”%(CLIENT_BASH64), ‘Content-Type’: “application/x-www-form-urlencoded”}
 req =, headers=paras, data=body)
 ACCESS_TOKEN = req.json()[‘access_token’]
 REFRESH_TOKEN = req.json()[‘refresh_token’]“Get user token successfully: Access_Token: %s Refresh_Token: %s”, ACCESS_TOKEN, REFRESH_TOKEN)
 import traceback
 LOG.error(“Unable to get user token”)
 return Nonedef get_user_devices(access_token):
 “”” The Get Device endpoint returns a list of the Fitbit devices connected to a user’s account.
 url = ‘'
 paras = {‘Authorization’: “Bearer %s”%(access_token)}
 req = requests.get(url, headers=paras)
 devices_info = json.dumps(req.json())“Get user devices info successfully: %s”, devices_info)
 return devices_info
 import traceback
 LOG.error(“Unable to get devices info”)
 return Nonedef get_user_activities(access_token):
 “”” The Get Daily Activity Summary endpoint retrieves a summary and list of a user’s activities and activity log entries for a given day in the format requested using units in the unit system which corresponds to the Accept-Language header provided.
 # Current date time in the format “yyyy-MM-dd”.
 date = time.strftime(“%F”)
 url = ‘' % date
 paras = {“Authorization”:”Bearer %s” % access_token}
 req = requests.get(url, headers=paras)
 activities_info = json.dumps(req.json())“Get user activities informantion successfully: %s”, activities_info)
 return activities_info
 import traceback
 LOG.error(“Unable to get user activities information.”)
 return Nonedef get_user_heartrate(access_token):
 “”” The Get Heart Rate Time Series endpoint returns time series data in the specified range for a given resource in the format requested using units in the unit systems that corresponds to the Accept-Language header provided.
 url = ‘'
 paras = {“Authorization”:”Bearer %s” % access_token}
 req = requests.get(url, headers=paras)
 heartrate_info = json.dumps(req.json())“Get user heartrate information successfully: %s”, heartrate_info)
 return heartrate_info
 import traceback
 LOG.error(“Unable to get user heartrate information.”)
 return Nonedef upload_to_streamr():
 “”” Upload the Fitbit Data to Streamr
 NOTE: Upload per minute
 global STREAM_ID
 global API_KEY
 url = ‘'+STREAM_ID+'/data'
 paras = {“Authorization”:”token %s” % API_KEY}
 result_devices = get_user_devices(ACCESS_TOKEN)
 if not result_devices:
 result_devices = “the Data not update” 
 result_activities = get_user_activities(ACCESS_TOKEN)
 if not result_activities:
 result_activities = “the Data not update”
 result_heartrate = get_user_heartrate(ACCESS_TOKEN)
 if not result_heartrate:
 result_heartrate = “the Data not update”
 body = (‘{“User Devices”: %s, “Daily Activities”: %s, “Daily HeartRate”: %s}’%(result_devices,result_activities,result_heartrate))“The Fitbit data is: %s”,body)
 thd.Timer(500, upload_to_streamr).start()
 req =, headers=paras, data=body)
 if req.status_code == 200 or req.status_code == 201:“Upload the Fitbit data to Streamr successfully.”)
 return req.status_code
 else:“Fail to upload the Fitbit data to Streamr. ERROR: %s”, req.status_code)
 import traceback
 LOG.error(“Fail to Upload the Fitbit data to Streamr.”)
 return Noneif __name__==”__main__”: 

Unless an error has occurred, you should be able to see your Fitbit fitness data in the stream!

Step 4: Publish the stream to the Streamr Marketplace

To sell your Fitbit Fitness Data on the Streamr Marketplace, you can follow the tutorial called “Creating a Product for the Streamr Data Marketplace”. It is important to keep in mind not to send any personal identifiable data to the Marketplace in order to protect users’ privacy right.