Read BloodPressure and BloodGlucose dataSource from google api fitness playground - google-fit

If I go to google api playground I do the following steps:
Step 1: Select & authorize APIs. I select the two scopes
https://www.googleapis.com/auth/fitness.blood_glucose.read
https://www.googleapis.com/auth/fitness.blood_pressure.read
cause I need to read blood glucose and pressure from user.
I select a google user and authorize the application to read the data.
Step 2: Exchange authorization code for tokens. I exchange the authorization token for the access and refresh token.
Step 3: Configure request to API. From List possible operations I choose
DataSources UsersLists all data sources that are visible to the developer, using the OAuth scopes provided. The list is not exhaustive; the user may have private data sources that are only visible to other developers, or calls using other scopes.
Request: GET https://www.googleapis.com/fitness/v1/users/{userId}/dataSources
I change {userId} with me and I suppose to retrieve the data source to read blood glucose and blood pressure, but what I receive is an empty array.
{
"dataSource": []
}
I need to test the reading of such values (pressure and glucose). What steps do I have to in google playground to achieve these 2 readings?
Thanks in advance

To get blood pressure and glucose data, you first need to create that data. You see in the get api that your datasource is empty. Here is what you can do to create and get a blood pressure:
Install "Instant Heart Rate Monitor" application from "play store",
Signup using your google account,
Connect "Instant Heart Rate Monitor" application to "Google Fit" (go to Instant Heart Rate Monitor profile and click on Google Fit,...)
Measure your heart bpm using this application. Since this app is now connected with Google Fit, you will have a record in your datasource.
To get this record, have the current epoch time in nanoseconds (https://www.epochconverter.com/) and make the following GET call:
https://www.googleapis.com/fitness/v1/users/me/dataSources/derived:com.google.heart_rate.bpm:com.google.android.gms:merge_heart_rate_bpm/datasets/000000-1518561964000000000
Note that in the above code, 1518561964000000000 is epoch time in nanoseconds and you need to change it to the current time. You can do the same thing for Glucose data with an application that measures blood Glucose :)

To get blood Pressure from google Fit endpoint is:
https://www.googleapis.com/fitness/v1/users/me/dataSources/derived:com.google.blood_pressure:com.google.android.gms:merged/datasets/0-1550664667715000000
dataStreamId: derived:com.google.blood_pressure:com.google.android.gms:merged
time: 0-1550664667715000000
This is startTime-endTime in UNIX epoch nanoseconds format.
To get epoch time this link can be used:
https://www.freeformatter.com/epoch-timestamp-to-date-converter.html

Related

[google-fit]; write my blood sugar data to Google Fit, but something went wrong(REQUIRES_APP_WHITELISTING) during the test

"OAuth 2.0 Client ID" was successfully obtained,but "OAuth consent Scree" was not verified
FitnessOptions fitnessOptions = FitnessOptions.builder()
.addDataType(HealthDataTypes.TYPE_BLOOD_GLUCOSE,FitnessOptions.ACCESS_WRITE)
.addDataType(HealthDataTypes.TYPE_BLOOD_GLUCOSE,FitnessOptions.ACCESS_READ)
.build();
DataSource mDataSource = new DataSource.Builder()
.setStreamName("test")
.setAppPackageName(context)
.setDataType(HealthDataTypes.TYPE_BLOOD_GLUCOSE)
.setType(DataSource.TYPE_DERIVED)
.build();
DataPoint bloodGlucose = DataPoint.builder(mDataSource)
.setField(HealthFields.FIELD_BLOOD_GLUCOSE_LEVEL,15)
.setTimestamp(now.getTimeMillis(),TimeUnit.MILLISECONDS)
.build();
DataSet dataSet = DataSet.builder(mDataSource)
.add(dataPoint)
.build();
Task<Void> response = Fitness
.getHistoryClient(context, GoogleSignIn.getAccountForExtension(context, fitnessOptions))
.insertData(dataSet);
I've passed the GoogleSignIn permission and an exception(com.google.android.gms.common.api.ApiException: 5024) has occurred when inserting data
please see: [https://developers.google.com/fit/scenarios/write-blood-glucose-data]
Does not allow the user to write blood sugar information anymore? or maybe there's something wrong with my code.
I would be very grateful if you could give us some suggestions based on your rich experience.
May be a little late, but if anyone else runs into this, the following may be of help.
From Google Fit docs:
Google Fit has health data types for measurements related to managing
general health (as opposed to fitness). Because health data can be
sensitive, these data types have sensitive scopes. This means you need
to apply for OAuth API verification for sensitive scopes on top of the
standard authorization permissions for Android and REST to read and
write to these data types.
Google will review your application and grant or deny verification.
Users will review the scope requests and grant or deny access to
these.
Note: Google has temporarily stopped taking new requests to write to health data types. We are updating our policy and process for
reviewing requests and will update this documentation again when we
resume.
As at 1 Jun 2021.
https://developers.google.com/fit/datatypes/health

Google Console - API key usage is really high when app is in development

I've build a small web app that asks a user to perform a Google OAuth login and submit their data in a form to a cloud function. All of this is using the same API Key but I'm seeing the usage in the last 30 days to be 2000+ when it's just me testing it. When I look at the usage of the cloud function I see 300 (which looks more realistic to me).
The API Key usage says it includes billable and non-billable requests, any way I can actually see the breakdown without having a surprise slap me in the face at the end of the month once the app goes live?
Any help would be greatly appreciated :)

How long do the new Places API session tokens last?

I have a website that uses address autocomplete on multiple pages--address book, shipping address, billing address. With the billing changes releasing next month, we can convert the Autocomplete process to use sessions instead of individual keystrokes. (https://cloud.google.com/maps-platform/user-guide/pricing-changes/#billing-changes)
How long is an AutocompleteSessionToken good for? The current page? An hour? Twelve? Permanently, with it counting against the limit each time it shows up in a new month?
If a session token does expire, and we send that token with a request, what's the result going to be? If the customer leaves a webpage open for a day and comes back to pick up, and our session data hasn't expired, how do we make sure they don't get autocomplete errors?
As far as I can see there is no official documentation regarding session duration for Places API in Google Maps Platform. I can share some information about sessions obtained from the technical support, however, it doesn't provide exact value for session duration and it looks like Google won't reveal the exact value.
First of all, if you use the built-in Autocomplete widget of Maps JavaScript API, it generates sessions for you automatically, so no need to worry about it.
If you create your own widget, you should be aware that sessions do not last very long. An autocomplete session includes some Autocomplete requests (to retrieve suggestions on a place as the user types), and at most one Places Details request (to retrieve details about the place selected by the user).
The same session token is passed to the Autocomplete and the subsequent Place Detail request.
A session starts with the first Autocomplete request (which typically happens when the user starts typing). Typically, a Places Details call is made after the user has selected one of the Autocomplete suggestions.
After a user has selected a place (for example, a Places Details call is made), a new session must be started, with a new session token.
A session token cannot be used for more than one user session. If a token is reused, the session will be considered invalid and the requests will be charged as if no session token was provided.
If session token is expired or invalidated you will be charged on the per keystroke basis. So each autocomplete request will be charged.
I hope you find this information useful.
As a customer of Google Maps, when we contacted their support team, an agent that worked with us told us that the timeout is 3 minutes.

What does this error mean?

Got the following in the logcat while using Google FIT api for android.
No live data sources available for Sensory Registration Request{type Data Type{com.google.calories.expended[calories(f)]}
I have registered a listner and the following request to get calories expended by the user:
SensorRequest sensorRequest = new SensorRequest.Builder().setDataType(DataType.TYPE_CALORIES_EXPENDED)
.setSamplingRate(10, TimeUnit.SECONDS).build();
Are you trying to fetch the data from the Google fit Cloud or from the sensors, if its cloud, go for HistoryAPI, and if its from sensors, may be the device doesn't have built in sensors to get calories burned, so try adding sensors via BLE with the help of BleAPI and then go for this call.
You have to get a proper response i believe

Implementing IoT PowerBI table schema

I'm currently implementing an IoT solution that has a bunch of sensors sending information in JSON format through a gateway.
I was reading about doing this on azure but couldn't quite figure out how the JSON scheme and the Event Hubs work to display the info on PowerBI?
Can I create a schema and upload it to PowerBI then connect it to my device?
there's multiple sides to this. To start with, the IoT ingestion in Azure is done tru Event Hubs as you've mentioned. If your gateway is able to do a RESTful call to the Event Hubs entry point, Event Hubs will get this data and store it temporarily for the retention period specified. Then stream analytics, will consume the data from Event Hubs and will enable you to do further processing and divert the data to different outputs. In your case, you can set one of the outputs to be a PowerBI dashboard which you can authorize with an organizational account (more on that later) and the output will automatically tied to PowerBI. The data schema part is interesting, the JSON itself defines the data table schema to be used on PowerBI side and will propagate from EventHubs to Stream Analytics to PowerBI with the first JSON package sent. Once the schema is there it is fixed and the rest of the data being streamed in should be in the same format.
If you don't have an organizational account at hand to use with PowerBI, you can register your domain under Azure Active Directory and use that account since it is considered within your org.
There may be a way of altering the schema afterwards using PowerBI rest api. Kindly find the links below..Haven't tried it myself tho.
https://msdn.microsoft.com/en-us/library/mt203557.aspx
Stream analytics with powerbi
Hope this helps, let me know if you need further info.
One way to achieve this is to send your data to Azure Events Hub, read it and send it to PowerBI with Stream Analytics. Listing all the steps here would be too long. I suggest that you take a look at a series of blog posts I wrote describing how I built a demo similar to what you try to achieve. That should give you enough info to get you started.
http://guyb.ca/IoTAzureDemo