我想通过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();