I am using userEvents.write method with from my web app.
I sent request a JSON like below with Authorization header got from gcloud auth application-default print-access-token
command.
{
"eventType": "detail-page-view",
"visitorId": "xxxxxxxxxx.xxxxxxxxxxxx",
"eventTime": "2021-03-06T09:13:58+09:00",
"experimentIds": [
"Gie-xxxxxxxxxxxxxxxxxxxxxxxx"
],
"userInfo": {
"userId": "",
"ipAddress": "xxx.xxx.xxx.xxx",
"userAgent": "Mozilla/5.0 (Linux; Android 11; Pixel 4a (5G)) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.181 Mobile Safari/537.36",
"directUserRequest": false
},
"uri": "https://xxxxx.net/aaaaaa/item/196160",
"referrerUri": "https://xxxxxxxx.net/item/196160",
"productDetails": [
{
"product": {
"id": "196160"
}
}
]
}
Request url is like this.
https://retail.googleapis.com/v2/projects/{PROJECT_NUMBER}/locations/global/catalogs/default_catalog/userEvents:write
In most case it goes well. But, sometime returns error below.
{
"error": {
"code": 401,
"message": "Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.googl
e.com/identity/sign-in/web/devconsole-project.",
"status": "UNAUTHENTICATED"
}
}
This error becomes not to appear after the app restart and it occures again after few days. Why this error occures? How can I fix it?