Google FIT Rest API Get Sessions - google-api

I'm trying to get sessions from a startDate to a EndDate, but every time i try return always a empty record
HTTP/1.1 200 OK
Content-length: 3
X-xss-protection: 1; mode=block
Content-location: https://www.googleapis.com/fitness/v1/users/me/sessions?startTime=2015-11-20T00:00:00.00Z&endTime=2015-11-30T23:59:59.99Z
X-content-type-options: nosniff
Expires: Fri, 01 Jan 1990 00:00:00 GMT
Vary: Origin,X-Origin
Server: GSE
Etag: ""
Pragma: no-cache
Cache-control: no-cache, no-store, max-age=0, must-revalidate
Date: Mon, 30 Nov 2015 16:49:52 GMT
X-frame-options: SAMEORIGIN
Content-type: application/json; charset=UTF-8
{}
Heres the URL :https://www.googleapis.com/fitness/v1/users/me/sessions?startTime=2015-11-20T00:00:00.00Z&endTime=2015-11-30T23:59:59.99Z
What is wrong?
I have data in that range and for example if i execute the dataset it return data (https://www.googleapis.com/fitness/v1/users/me/dataSources/derived:com.google.step_count.delta:com.google.android.gms:estimated_steps/datasets/XXXXXXX000000000000-XXXXXX000000000000 )

Sessions represent a time interval during which users perform a fitness activity.
It will only appear to the sessions resource items that have been converted to a session.
Normally, automatic tracks (the ones that you don't do anything to track) only become sessions when you put a name on it (you can try it using Google Fit App, selecting one of the auto track activities, put a name of it, like "lunch walk"). It takes a while to become available in the API, in my case, it took one hour to become available to the sessions list.
Another aproach to see itens on the session list is to create a session : create a new activity on Google Fit, with start and stop actions.
You may find more information about the session concept here: https://developers.google.com/fit/android/using-sessions

Related

Dynamics CRM + Execute requests in parallel

I have a complex azure function which creates/updates approx 400 records in a table in dataverse while checking several conditions
I am using ExecuteTransactionRequest to create/update the records and it takes around 15 seconds to perform the logic. Is there a way I can make it faster, introduce parallel processing along with executetransation?
I'm not sure if my answer is applicable in your scenario, but I'll mention it for reference.
WebApi accepts a batch requests which saves you the latency time of sequential and concurrent requests. One request with multiple internal requests is sent once to the api and will run on their servers at once and get back the results.
That is if you are using WebApi and not using connectors to communicate with CDS.
If so, please refer to the following example to post 2 currencies and get all:
--batch_ABC123
Content-Type: multipart/mixed; boundary=changeset_ABC111
--changeset_ABC111
Content-Type: application/http
Content-Transfer-Encoding: binary
POST YOUR-RESOURCE_URL/api/data/v9.1/transactioncurrencies HTTP/1.1
Content-ID: 1
Accept: application/json;
Content-Type: application/json;type=entry
{"currencyname": "Dansk Krona1","currencysymbol": "$","isocurrencycode": "PPV","exchangerate": 0.90}
--changeset_ABC111
Content-Type: application/http
Content-Transfer-Encoding: binary
POST YOUR-RESOURCE_URL/api/data/v9.1/transactioncurrencies HTTP/1.1
Content-ID: 2
Accept: application/json;
Content-Type: application/json;type=entry
{"currencyname": "Dansk Krona2","currencysymbol": "$","isocurrencycode": "UPV","exchangerate": 0.90}
--changeset_ABC111--
--batch_ABC123
Content-Type: application/http
Content-Transfer-Encoding:binary
GET YOUR-RESOURCE_URL/api/data/v9.1/transactioncurrencies HTTP/1.1
Accept: application/json
--batch_ABC123--

Etcd - Outdated index. How to read "X-Etcd-Index" from client

I am using github.com/coreos/etcd/client for communicating with etcd cloud, sometimes i am receiving 401 error "The event in requested index is outdated and cleared" , on server page there is a explanation why it happened and how it can be solved. Actually I want to implement the following scenario.
Get "key" and its modified index
do some job
start watching on "key" from modified index
this way I can be shure that all changes during 2 step will be also received. But Etcd saves only top N changes and sometimes I am receiving 401 error. Acording docu I can use "X-Etcd-Index" + 1 header from Get key request as modified index to watch.
curl 'http://127.0.0.1:2379/v2/keys/foo' -vv
< HTTP/1.1 200 OK
< Content-Type: application/json
< X-Etcd-Cluster-Id: f63cd37d2ff4f650
< X-Etcd-Index: 17245
< X-Raft-Index: 2107637
< X-Raft-Term: 360
< Date: Tue, 15 Dec 2015 09:02:20 GMT
< Content-Length: 791
< ...
But I don't use direct http calls , only github.com/coreos/etcd/client. How can I get (and is it actually possible using api) a http header info on from get key request ?
The X-Etcd-Index header corresponds to the Response.Index field.
The index is available in the response field as the "Index" object. See the documentation here: https://godoc.org/github.com/coreos/etcd/client#Response

Dailymotion API return very old cached version

My application load regulary the number of viewers watching a livestream on dailymotion.
I use the dailymotion API with the field "audience" to do that.
But the server is sending to me a really really old cached version of the precious JSON file.
For example, a streamer is live since 2 hours, but the API is sending this to me :
curl https://api.dailymotion.com/video/x25eyo8?fields=audience
{"audience":0}
If i add another field just a few seconds later, just to see :
curl https://api.dailymotion.com/video/x25eyo8?fields=audience,onair
{"audience":1177, onair: true}
And if I re-send the first request
curl https://api.dailymotion.com/video/x25eyo8?fields=audience
{"audience":0}
More interesting, the headers sent by the server show this :
curl -I https://api.dailymotion.com/video/x25eyo8?fields=audience
HTTP/1.1 200 OK
Server: DMS/1.0.42
X-Dm-Api-Object: video
X-DM-BackNode: web-011.adm.dailymotion.com:80
Cache-Control: public, max-age=10, stale-if-error=900
X-Dm-Api-Method: info
Content-Type: application/json; charset=UTF-8
X-DM-LB: 195.8.215.130
Access-Control-Allow-Origin: *
X-DM-BackNode-Response-Time: 47
Etag: W/"8xO_txIM6arAYYIALcRUgg"
X-Robots-Tag: noindex
Last-Modified: Fri, 06 Nov 2015 20:20:31 GMT
Access-Control-Allow-Headers: Content-Type, Authorization
Access-Control-Allow-Methods: GET, POST, DELETE
X-Dm-Page: fr.rest.rest_api
Via: 1.1 varnish
Fastly-Debug-Digest: 1d9daef237214a02cb79d06c44fdaa26329d5bd16c9afda535f3f9b104438b84
Content-Length: 17
Accept-Ranges: bytes
Date: Mon, 30 Nov 2015 01:16:59 GMT
Via: 1.1 varnish
Age: 116
Connection: keep-alive
X-Served-By: cache-fra1225-FRA, cache-lhr6323-LHR
X-Cache: HIT, MISS
X-Cache-Hits: 1, 0
Vary: X-DM-EC-Geo-Country, Accept-Encoding
Age : 116 with a max-age of 10 ?
And even when i receive an "up to date" version (age < 10), the file still contains 0 viewers whereas the stream is online and 1000+ viewers are watching.
Now there are 2 questions :
Why this happens ?
Can I force a non-cached version ?
Thanks for your help.
EDIT :
It looks like it's the same problem when you watch a stream on http://games.dailymotion.com/. For all channels, numbers of viewers are correct inside the player but for some ones, the number displayed under it is not (most of the time, it indicate 0)
Example of wrong number of viewers

Varnish cache miss with json content type

I'm using the following vcl to help me determine if I'm getting a Varnish cache hit or a miss:
sub vcl_deliver {
if (obj.hits > 0) {
set resp.http.X-Varnish-Cache = "HIT";
}
else {
set resp.http.X-Varnish-Cache = "MISS";
}
}
This is working fine, but not for application/json content type.
I'm getting X-Varnish-Cache = "MISS" on every request, but I can't see why this would be happening (and I have a suspicion that it's a false negative).
Here's an example of the response headers for my (apparently) non cached json request:
Accept-Ranges:bytes
Age:0
Cache-Control:public, max-age=10800
Connection:keep-alive
Content-Encoding:gzip
Content-Length:2139
Content-Type:application/json
Date:Thu, 09 Jan 2014 16:08:21 GMT
Etag:"1389283199-1"
Expires:Sun, 19 Nov 1978 05:00:00 GMT
Last-Modified:Thu, 09 Jan 2014 15:59:59 +0000
Server:Apache
Vary:Cookie,Accept-Encoding
Via:1.1 varnish
X-Drupal-Cache:HIT
X-Powered-By:PHP/5.3.23
X-Varnish:544296535
X-Varnish-Cache:MISS
If I look at the response times, it's 8 times quicker on subsequent requests to the same url (so 800ms for the first time, and 100ms the second and then on). This makes me think that Varnish is caching, but my vcl is incorrect.
I should also add that no cookies are being sent with the request, and it's a GET request.
Your VCL is correct (BTW: when varnish response comes from cache X-Varnish header comes with 2 numbers).
The response times improves due to Drupal caching.
Probably JSON is not being cached because of the cookies or your VCL.
You have a working VCl for drupal on https://github.com/NITEMAN/varnish-bites/blob/master/varnish3/drupal-base.vcl
Anyway, to trace the issue your full VCL and a varnishlog trace of the request.

Cache-control: why two different max-ages

I'm reading an atom-feed from Twitter. I want to know how often I should consult the feed (i.e. throw it the query URL), in order not to miss any results.
The header cache-control line has two different max-ages:
Cache-Control: max-age=15, must-revalidate, max-age=300
How should I interpret this? Should I poll every 15 seconds, or every 300 seconds?
Any learned comment would be appreciated.

Resources