我正在为我们当前的项目使用 Google Fit REST API。我们可以添加一些数据源,但有些数据源无法添加。我们已经遵循了文档。一些请求返回这种错误消息(我们甚至在他们的 OAuth Playground 中尝试过)
"error": {
"status": "INVALID_ARGUMENT",
"message": "Data type does not match well-known data type with the same name",
"code": 400,
"errors": [
{
"reason": "invalidArgument",
"message": "Data type does not match well-known data type with the same name",
"domain": "global"
}
]
}
我们正在尝试添加的是我们已经允许其权限范围的数据源
https://www.googleapis.com/auth/fitness.activity.read
https://www.googleapis.com/auth/fitness.activity.write
{
"application": {
"name": "PersonalPulse",
"version": "1.0.0"
},
"dataType": {
"name": "com.google.activity.exercise",
"field": [
{
"name": "exercise",
"format": "integer"
},
{
"name": "repetitions",
"format": "integer"
},
{
"name": "resistance type",
"format": "integer"
},
{
"name": "resistance",
"format": "floatPoint"
},
{
"name": "duration",
"format": "integer"
}
]
},
"device": {
"manufacturer": "browser",
"model": "browser",
"type": "unknown",
"uid": "2",
"version": "10"
},
"type": "derived"
}
我们按照此处文档的说明进行操作 https://developers.google.com/fit/datatypes/activity#workout
我们使用 PHP/Laravel 框架作为健身 api,使用 cURL 来处理 http 请求。如果有人知道我们为什么会收到错误,请提供帮助。谢谢。
您还可以在此处的 Google Playground 中尝试并粘贴范围 https://developers.google.com/oauthplayground/
最佳答案
您的请求的第一个问题是您传入的 exercise
是一个 integer
字段,但是 the documentation说你需要传入一组枚举的字符串之一(我不知道为什么它在那里说 int
,但如果你点击“接受的值”,你可以看到那些肯定不是' t 整数...)。
但是,如果您根本不指定字段,事情会更容易。只需指定数据类型名称:
// ...
"dataType": {
"name": "com.google.activity.exercise",
}
// ...
正确的字段将在后端填写并返回给您。
关于php - Google Fit API 无法添加大部分范围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63192445/