数据归因
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
Google 健身中的每个数据点都有一个关联的数据源。数据源包含的信息用于标识收集或转换数据的应用或设备。
借助 REST API,您可以确定是哪个应用插入了健身数据。例如,一款分析用户健身历史记录中的各种数据的应用可能希望向用户显示分析中包含的健身时段列表,以及有关每个时段插入的是哪个应用的信息。
借助 REST API,您还可以将在健身存储区中插入的数据与应用相关联。
确定是哪个应用插入了数据
要获取插入会话的 Android 应用的软件包名称或已插入会话的 REST 应用的名称,请执行以下操作:
- 检索会话。
- 查看
session.application.packageName
或 session.application.name
属性。
要获取 Android 应用的软件包名称或插入数据集的 REST 应用的名称,请执行以下操作:
- 检索数据集。
- 通过读取
dataset.dataSourceId
属性来检索数据源。
- 查看
dataSources.application.packageName
或 dataSources.application.name
属性。
application
属性包含以下字段:
name
- 应用的名称。
packageName
- Android 应用的软件包名称。
detailsUrl
- (可选)用于链接到应用的 URI。
当您在应用中列出一定时间间隔内的所有可用会话时,您可以使用这些信息向用户显示每个会话插入的是哪个应用。
如需将插入健身存储区的数据归因于您的应用,请确保:
访问您插入的数据的应用可以使用此信息将该数据归因于您的应用。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-31。
[null,null,["最后更新时间 (UTC):2025-08-31。"],[[["\u003cp\u003eEvery data point in Google Fit is linked to a data source, which identifies the source app or device.\u003c/p\u003e\n"],["\u003cp\u003eThe Google Fit REST API allows you to identify the app that inserted specific fitness data, like sessions or datasets.\u003c/p\u003e\n"],["\u003cp\u003eYou can attribute data you insert into Google Fit to your application by including application details when creating data sources.\u003c/p\u003e\n"],["\u003cp\u003eThis attribution allows other apps to correctly identify your application as the source of the data.\u003c/p\u003e\n"]]],[],null,["# Data Attribution\n\nEvery data point in Google Fit has an associated data source. Data sources contain\ninformation to identify the app or the device that collects or transforms the data.\n\nThe REST API lets you determine which app inserted fitness data.\nFor example, an app that analyzes a variety of data from the user's fitness history may\nwant to present users with the list of fitness sessions included in the analysis, along with\ninformation about which app inserted each session.\n\nThe REST API also lets you associate data that you insert in the fitness store with your\napplication.\n\nDetermine which application inserted data\n-----------------------------------------\n\nTo obtain the package name of the Android application that inserted a session or\nthe name of the REST application that inserted a session:\n\n1. Retrieve the session.\n2. Read the [`session.application.packageName`](/fit/rest/v1/reference/users/sessions/list#session.application.packageName) or [`session.application.name`](/fit/rest/v1/reference/users/sessions/list#session.application.name) property.\n\nTo obtain the package name of the Android application or\nthe name of the REST application that inserted a dataset:\n\n1. Retrieve the dataset.\n2. Retrieve the data source by reading the [`dataset.dataSourceId`](/fit/rest/v1/reference/users/dataSources/datasets#dataSourceId) property.\n3. Read the [`dataSources.application.packageName`](/fit/rest/v1/reference/users/dataSources#application.packageName) or [`dataSources.application.name`](/fit/rest/v1/reference/users/dataSources#application.name) property.\n\nThe `application` property contains these fields:\n\n`name`\n: The name of the application.\n\n`packageName`\n: The package name of the Android application.\n\n`detailsUrl`\n: (Optional) A URI to link to the application.\n\nWhen you list all available sessions for a time interval in your application, you can\nuse this information to show your users which app inserted each session.\n\nProvide information about your application\n------------------------------------------\n\nTo attribute data you insert into the fitness store to your application, ensure that:\n\n- You add your application details to the [`dataSources.application`](/fit/rest/v1/reference/users/dataSources#application) property when creating data sources.\n- You specify the correct [`datasets.dataSourceId`](/fit/rest/v1/reference/users/dataSources/datasets) for your data source when adding points to datasets.\n\nApplications accessing data you inserted can use this information to attribute that data to your\napplication."]]