【问题标题】:Google Fit API Cannot add most of the scopesGoogle Fit API 无法添加大部分范围
【发布时间】:2020-07-31 13:06:51
【问题描述】:

我正在为我们当前的项目使用 Google Fit REST API。我们可以添加一些数据源,但有些我们不能添加。我们已经按照文档进行了操作。一些请求正在返回这种错误消息(我们甚至在他们的 OAuth 操场上尝试过)

"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 框架用于 Fitness api 和 cURL 用于 http 请求。如果有人知道我们为什么会收到错误,请提供帮助。谢谢。

您也可以在此处的 google playground 中尝试并粘贴范围 https://developers.google.com/oauthplayground/

【问题讨论】:

    标签: php json laravel google-api google-fit


    【解决方案1】:

    您的请求的第一个问题是您传入的 exercise 是一个 integer 字段,但 the documentation 表示您需要传入一组枚举字符串中的一个(我不知道为什么那里说int,但是如果你点击“接受的值”,你可以看到那些绝对不是整数......)。

    但是,如果您根本不指定字段会更容易。只需指定数据类型名称:

    // ...
    "dataType": {
      "name": "com.google.activity.exercise",
    }
    // ...
    

    后台会填写正确的字段并返回给您。

    【讨论】:

    • 那么先生的正确值应该是多少?我们甚至尝试过back_extension,但它不起作用
    • back_extension 是什么?您似乎在询问创建数据源,而不是向其中添加数据。
    • 我们甚至尝试了文档中的所有数据类型,包括字符串。还是不行
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-03
    • 1970-01-01
    相关资源
    最近更新 更多