通过REST阅读我的Google健身数据

时间:2016-10-03 04:32:21

标签: c# rest google-api gps google-fit

我想通过REST API以编程方式阅读我的Google Fit GPS数据。我能够获得一个数据源列表,但我似乎无法获得任何会话或数据集结果。

例如:

GET https://www.googleapis.com/fitness/v1/users/me/sessions?oauth_token=mytoken

POST https://www.googleapis.com/fitness/v1/users/me/dataset:aggregate?oauth_token=mytoken
{"aggregateBy": [{"dataTypeName": "com.google.location.sample"}]}

我错过了什么?我的应用程序甚至可以下载不负责存储的数据吗?

FWIW,我在C#中使用了以下Google.Apis.Fitness.v1包测试代码:

var credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
    new ClientSecrets
        {
            ClientId = "myid",
            ClientSecret = "mysecret"
        },
    new[]
        {
            FitnessService.Scope.FitnessLocationRead,
            FitnessService.Scope.FitnessActivityRead,
            FitnessService.Scope.FitnessBodyRead
        },
    "user",
    CancellationToken.None,
    new FileDataStore("google-fit.json", true));
var service = new FitnessService(
    new BaseClientService.Initializer {HttpClientInitializer = credential});
var dataSources = await service.Users.DataSources.List("me").ExecuteAsync();
var sessions = await service.Users.Sessions.List("me").ExecuteAsync();
var dataSets = await service.Users.Dataset.Aggregate(
    new AggregateRequest {AggregateBy = new[] {
        new AggregateBy {DataTypeName = "com.google.location.sample"}}}, "me")
    .ExecuteAsync();

0 个答案:

没有答案