【发布时间】:2019-11-13 15:29:55
【问题描述】:
我喜欢获取用户浏览器报告谷歌分析中可用的用户 ID。 我正在使用下面的 batchGet 来获取使用 ga:clientId 的用户 ID 列表 https://developers.google.com/analytics/devguides/reporting/core/v4/rest/v4/reports/batchGet
我能够获取客户端 ID,但是在尝试使用以下 API 相同的 ID 时 https://developers.google.com/analytics/devguides/reporting/core/v4/rest/v4/userActivity/search#request-body
未找到其返回的 400 错误。 即使我复制了在谷歌分析的用户资源管理器报告仪表板中可见的用户 ID,它仍然返回 400 未找到错误。 是不是我做错了什么?
代码sn-p
analytics = build('analyticsreporting', 'v4', credentials=credentials)
body={
"viewId": VIEW_ID,
"user": {
"type": "USER_ID", # I have tried CLIENT_ID Also
"userId": user_id # For now I have copied the value directly from the user explorer from browser itself for testing.But it didn't worked
}
}
result=analytics.userActivity().search(body=body).execute()
回应
Traceback(最近一次调用最后一次):文件“ga_session_data.py”,行 192,在 ga.main() 文件“ga_session_data.py”,第 178 行,在 main 结果=analytics.userActivity().search(body=body).execute() 文件“env/lib/python3.6/site-packages/googleapiclient/_helpers.py”, 第 130 行,在 positional_wrapper 中 返回包装的(*args,**kwargs)文件“env/lib/python3.6/site-packages/googleapiclient/http.py”, 第 856 行,执行中 引发 HttpError(resp, content, uri=self.uri) googleapiclient.errors.HttpError: https://analyticsreporting.googleapis.com/v4/userActivity:search?alt=json 返回“CLIENT_ID: XXXXXXXX 未找到。”>
【问题讨论】:
标签: python google-analytics google-reporting-api