I'm trying to access a user's activity in google analytics using python 3.7...I've gone through the process of getting an access token and using the code from here
https://developers.google.com/analytics/devguides/reporting/core/v4/user-reporting
The credentials work if I'm just downloading aggregate data but when I use this approach I get a 401 message that says
"message": "Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential., "status": "UNAUTHENTICATED"
If I go to the OAuth 2.0 Playground, the access token works fine. Any ideas what I'm missing here? Thanks.
url = 'https://analyticsreporting.googleapis.com/v4/userActivity:search'
payload = {
"viewId": "xxx",
"user": {
"type": "CLIENT_ID",
"userId": "xxx"
},
"dateRange": {
"startDate": "2019-06-13",
"endDate": "2019-10-05",
}
}
hed = {
'Authorization': 'Bearer ' + access_token,
'Content-type': 'application/json'
}
r = requests.post(url, data=payload, headers=hed)