研究 API 作为研究调查员,您可以通过 Web 前端检索、删除和管理所有贡献的记录,也可以在研究页面中直接链接,也可以使用 API 进行检索、删除和管理。如果您想自动化大规模研究,该 API 非常有用。要使用 API,您需要具有研究的标识符和 .两者都可以在 App 的 Study 页面下找到或生成。 对于 ,转到 Studies (研究) 屏幕,然后选择 As Investigator (作为研究者) 选项卡。点按 研究 ,然后点按标题下的 研究 ID 以复制标识符。 对于 ,转到 Studies (研究) 屏幕,然后选择 As Investigator (作为研究者) 选项卡。点按 研究 ,然后选择 数据 选项卡。点按 生成新代码 以生成新的密码。
作为研究调查员,您可以通过 Web 前端检索、删除和管理所有贡献的记录,也可以在研究页面中直接链接,也可以使用 API 进行检索、删除和管理。如果您想自动化大规模研究,该 API 非常有用。要使用 API,您需要具有研究的标识符和 .两者都可以在 App 的 Study 页面下找到或生成。studyId``secretCode
studyIdsecretCode⚠️ 重要通知:Study API 目前处于测试阶段,可能会发生变化。使用 API 时,您可能会遇到错误或问题。我们建议您进行全面测试并报告您发现的任何问题。请注意适用于所有 API 终端节点的速率限制。
下面的示例代码是用 Python 编写的,但您可以随意将其调整为所选的任何语言或工具。
使用 GET 方法列出带有 ID 和密码的研究的所有记录和用户:test``secret
import requests studyId = "test" # replace with real id secretCode = "secret" # replace with real secret, but be mindful not to commit it to git! url = f"https://sensorlogger.app/api/study/v1?studyId={studyId}" response = requests.get(url, headers={"Authorization": secretCode}) print(response.json())
JSON 响应示例如下:
{ "recordings": [ { "uploadId": "97b996e6-7ace-489f-ae65-57bcef27ae47", "name": "Tedt-2024-05-15_21-38-32.zip", "size": 245407, "userId": "98f90cf0f204", "questionAnswers": {} } ], "users": [{ "userId": "98f90cf0f204", "questionAnswers": { "What is your favourite colour?": "Blue" } }] }
有关 Schema 的更多信息,请参阅 https://github.com/tszheichoi/awesome-sensor-logger/blob/main/QUESTIONNAIRE.md。questionAnswers
使用 GET 方法将研究 ID 和密钥代码的特定上传 ID 下载到名为的文件中:uploadId``test``secret``test.zip
import requests studyId = "test" secretCode = "secret" uploadId = "uploadId" url = f"https://sensorlogger.app/api/study/file/v1?studyId={studyId}&uploadId={uploadId}" response = requests.get(url, headers={"Authorization": secretCode}) with open(f"{uploadId}.zip", "wb") as f: # Change the extension if needed f.write(response.content)
如果您已将 Study 导出配置为非 Zip 格式(例如.zip``.json)
使用 DELETE 方法删除研究 ID 和密钥代码的特定上传 ID。请注意,删除需要研究所有者拥有 Pro 或 Ultimate 订阅。uploadId``test``secret
import requests studyId = "test" secretCode = "secret" uploadId = "uploadId" url = f"https://sensorlogger.app/api/study/file/v1?studyId={studyId}&uploadId={uploadId}" response = requests.delete(url, headers={"Authorization": secretCode}) print(response.json())
JSON 响应示例如下: