New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Analytics-Data] Oauth2 Authentication #3975
Comments
The following seems to work for oAuth authentication wise:
Still working on getting the first report to show up though... Some docs here as well: #3975 |
Whoops - meant to link to this PR instead: googleapis/php-analytics-data#2. Long night. ;) Note that link is for the v1alpha which is slightly different, most notably that sample provides an Here's a sample (app-specifics redacted) of how I got it working. And yes, v3 oauth tokens are valid for v4 too. First creating an OAuth2 instance with as much relevant tokens as are available that'll be used in different places:
(I've also seen some mention of the OAuth client having built-in storage, but I'm handling it outside of that.) And using those credentials for running a minimal report and parsing that into a somewhat usable associative array structure dumped to screen:
As my use case lets a user choose the profile to show reports for, it's also using the
I haven't finished upgrading the authorization step yet (this is an upgrade from the previous API so I already had a valid refresh_token to use and it was really late last night), but from what I've gathered so far that'll start with creating the auth url:
Then providing the code to the oauth object and calling fetchAuthToken which will exchange the code for a refresh and access token available via their setters to persist somewhere in the app.
I have no idea if this is all the officially recommended approach as the documentation is spotty at best, but it does seem to work. |
I think this is answered now. closing |
Hi,
We can use already authorised oAuth2 credentials for Analytics Reporting API v4 or v3 with this GA4 property data fetch?
Or we need to use service account strictly?
Thanks,
Moved from https://github.com/googleapis/php-analytics-data/issues/4
cc @chiragvels
The text was updated successfully, but these errors were encountered: