【发布时间】:2021-09-01 10:02:37
【问题描述】:
请帮忙。
我有一个从 Google Analytics 中删除用户数据的云功能,当我从后端发送带有删除请求的 Pub/Sub 消息时会触发此功能。我正在使用在我的 Google Cloud Console 上激活的 Google Analytics API。
我关注了这个文档:https://developers.google.com/analytics/devguides/config/userdeletion/v3,但是我没有成功通过云功能删除用户。
云功能:
function deleteGArecord(userObject) {
const options = {
method: "POST",
url: "https://www.googleapis.com/analytics/v3/userDeletion/userDeletionRequests:upsert",
headers: {
//"Content-Type": "application/json",
},
body: JSON.stringify({
kind: "analytics#userDeletionRequest",
id: {
type: "CLIENT_ID",
userId: userObject.clientId,
},
webPropertyId: "UA-111111-000",
}),
};
request(options, function (error, response) {
if (error) {
console.log(error);
}
console.log("ga user delete request:" + JSON.stringify(response));
});
}
我尝试了什么:
- 创建 OAuth 客户端 ID - 应用程序类型 web。
- 在我的 Analytics 媒体资源中添加了此客户。
- 发送删除请求时调用该函数。
云功能日志:
"statusCode":401,"body":"{\n \"error\": {\n \"code\": 401,\n \"message\": \"Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.\",\n \"errors\": [\n {\n \"message\": \"Login Required.
我如何验证我的云功能才能发送此命中。我已经创建了用户,并且正在从 ClientId 所在的同一个项目中调用此函数...
提前致谢!
【问题讨论】:
标签: google-cloud-functions google-oauth google-analytics-api