php - Google Fit API 无法添加大部分范围

标签 php json laravel google-api google-fit

我正在为我们当前的项目使用 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/

相关文章:

PHPExcel写Excel并保存到服务器?

php - 如何通过带有json的ajax响应获取超过1个结果

php - 使用 Twig 生成 JSON

javascript - Vue.js 2.5 列表渲染

javascript - 单击按钮后将数据插入数据库

javascript - 输入正确值后重新加载网页

javascript - 将下拉多个复选框插入到 mysql 数据库

PHP + MySQL 查询 : Unexpected results (for small number of results only)

javascript - 无法将 JSON 文本响应中的 & 替换为 &

laravel - Vue-router:如果用户没有权限,则重定向到路由