php - Google fit REST API 无法添加部分数据源
问题描述
我正在尝试添加特定的数据源,范围是
https://www.googleapis.com/auth/fitness.activity.read
https://www.googleapis.com/auth/fitness.activity.write
但是当我尝试这样做时。它返回给我一个错误
{
"reason": "invalidArgument",
"message": "Data type does not match well-known data type with the same name",
"domain": "global"
}
我向这个 URL 发送 POST 请求
https://www.googleapis.com/fitness/v1/users/me/dataSources
这是我的请求正文
{
"dataStreamName": "MyDataSource",
"type": "derived",
"application": {
"detailsUrl": "http://example.com",
"name": "Foo Example App",
"version": "1"
},
"dataType": {
"field": [
{
"name": "activty_type",
"format": "integer"
}
],
"name": "com.google.activity.segment"
},
"device": {
"manufacturer": "Example Manufacturer",
"model": "ExampleTablet",
"type": "tablet",
"uid": "1000001",
"version": "1.0"
}
}
我使用 PHP/Laravel 作为一种语言,我使用 CURL 作为 http 请求库。有人能告诉我我做错了什么吗?某些范围已成功添加,但有些范围无法添加。
谷歌文档参考:https ://developers.google.com/fit/datatypes/activity?authuser=3
解决方案
根据文档,activity_type (您有错字)不是正确的字符串。com.google.activity.segment
需要activity
字段。
请参阅文档。
因此,当它在 Google Fit API 测试控制台中返回预期的资源和 HTTP 200 时,这将起作用:
{
"dataStreamName": "MyDataSource",
"type": "derived",
"application": {
"detailsUrl": "http://example.com",
"name": "Foo Example App",
"version": "1"
},
"dataType": {
"field": [
{
"name": "activity",
"format": "integer"
}
],
"name": "com.google.activity.segment"
},
"device": {
"manufacturer": "Example Manufacturer",
"model": "ExampleTablet",
"type": "tablet",
"uid": "1000001",
"version": "1.0"
}
}
推荐阅读
- python - 如果文件同时包含二进制代码和文本,如何使用 python 替换文本?
- django - form.is_valid() 在 Django 单元测试中失败
- java - 快速访问超类中私有数组或数组列表的对象项
- docker - ekito/cron 作业教程出错
- nuxt.js - Nuxt.js 仅在首次加载时加载静态文件夹 js
- magento-1.9 - Magento 1.9 header.phtml 文件未读取
- ansible - scl enable rh-mariadb102 bash 不适用于 Ansible 剧本
- open-source - 开源游戏可以在商业游戏机上发布/发布吗?
- java - 如何使用查询 findByClassLiteral 构建自定义 MongoRepository
- ruby-on-rails - Gem::Ext::BuildError: 错误: 无法构建 gem 原生扩展。Ubuntu 18.04