调用GoogleFit API:CURL请求成功,CFHTTP返回404错误
ColdFusion调用Google Fit API /dataset:aggregate端点返回404问题
调用Google Fit API的/fitness/v1/users/me/dataset:aggregate端点时,完全相同的请求参数通过curl命令和JavaScript的fetch方法都能成功获取数据,但使用ColdFusion的cfhttp组件发起请求却返回404错误,直接在浏览器中访问该端点也会得到404。
已连续多日排查仍未找到问题根源,希望有人帮忙指出错误。
ColdFusion代码
<cfhttp method="POST" result="stepsResponse" url="https://www.googleapis.com/fitness/v1/users/me/dataset:aggregate"> <cfhttpparam type="header" name="Authorization" value="Bearer #ACCESS_TOKEN#"> <cfhttpparam type="header" name="Content-Type" value="application/json;encoding=utf-8"> <cfhttpparam type="body" value='{"bucketByTime":{"durationMillis":86400000},"endTimeMillis":1678950000000,"startTimeMillis":1678863600000,"aggregateBy":[{"dataSourceId":"derived:com.google.step_count.delta:com.google.android.gms:estimated_steps","dataTypeName":"com.google.step_count.delta"}]}'> </cfhttp>
curl命令
curl \ -X POST \ -H "Content-Type: application/json;encoding=utf-8" \ -H "Authorization: Bearer {ACCESS_TOKEN}" \ -d '{"bucketByTime":{"durationMillis":86400000},"endTimeMillis":1678950000000,"startTimeMillis":1678863600000,"aggregateBy":[{"dataSourceId":"derived:com.google.step_count.delta:com.google.android.gms:estimated_steps","dataTypeName":"com.google.step_count.delta"}]}' \ https://www.googleapis.com/fitness/v1/users/me/dataset:aggregate
JavaScript fetch代码
fetch('https://www.googleapis.com/fitness/v1/users/me/dataset:aggregate', { method: 'POST', headers: { 'Authorization': '#ACCESS_TOKEN#', 'Content-Type': 'application/json;encoding=utf-8' }, body: '{"bucketByTime":{"durationMillis":86400000},"endTimeMillis":1678950000000,"startTimeMillis":1678863600000,"aggregateBy":[{"dataSourceId":"derived:com.google.step_count.delta:com.google.android.gms:estimated_steps","dataTypeName":"com.google.step_count.delta"}]}' }) .then(response => response.json()) .then(response => console.log(response)) .catch(err => console.error(err));

内容的提问来源于stack exchange,提问作者Chris Geirman
相关产品推荐
相关产品推荐

