[ANALYTICS-420] Investigate why request had invalid authentication credentials in GA4 Created: 05/Apr/23  Updated: 25/May/23  Resolved: 14/Apr/23

Status: Closed
Project: Analytics
Component/s: None
Affects Version/s: None
Fix Version/s: 1.2.3

Type: Spike Priority: Neutral
Reporter: Thuy To Assignee: Alberto Soto
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: 5.5h
Original Estimate: Not Specified

Attachments: File authorxga4-key.json     PNG File image-2023-04-05-16-58-46-847.png     PNG File image-2023-04-05-17-44-46-833.png    
Issue Links:
dependency
depends upon ANALYTICS-408 Migrating to the Google Analytics Dat... Closed
relation
Template:
Date of First Response:
Epic Link: Google Analytics 4
Story Points: 3
Team: AuthorX
Work Started:

 Description   

+ Sample yaml configuration:

class: info.magnolia.analytics.google.datasource.GoogleDataSupplier

credentials:

  applicationName: Magnolia Analytics

  serviceAccountJsonPath: /google-analytics/dataSuppliers/authorxga4-key.json

parameters:

  propertyId: 354424382

  startDate: 7DaysAgo

  endDate: today

  dimensionName: date

  metricExpression: sessions

+ Document refer: https://github.com/googleapis/java-analytics-data

 

+ Problem: When running to get the GA4 report on Analytics module of Magnolia, it throws this error.

io.grpc.StatusRuntimeException: UNAUTHENTICATED: Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.



 Comments   
Comment by Thuy To [ 14/Apr/23 ]

This problem io.grpc.StatusRuntimeException: UNAUTHENTICATED: Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. is fixed when using info.magnolia.resourceloader.Resource with .openStream() method.

Solution

GoogleCredentials credentials = GoogleCredentials.fromStream(serviceAccountJsonResource.openStream())
.createScoped(Collections.singleton("https://www.googleapis.com/auth/analytics"));

Generated at Sun Feb 11 23:18:42 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.