資料歸因
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
Google Fit 中的每個資料點都有相關聯的資料來源。資料來源包含識別應用程式,或是用來收集或轉換資料的裝置資訊。
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。
在應用程式中列出特定時間間隔的所有可用工作階段時,您可以利用這項資訊向使用者顯示插入每個工作階段的應用程式。
如要將插入健身商店的資料歸因至應用程式,請確認下列事項:
存取您插入資料的應用程式可以使用此資訊,將該資料歸因於您的應用程式。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-31 (世界標準時間)。
[null,null,["上次更新時間: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."]]