I'd like to access the Google Analytics Admin API on behalf of other users. I have a valid oAuth2 access token from the Oauth2 dialog flow with authentication window popup.
Google offers new Cloud Client Libraries or older Google API Client Libraries for access to their services.
Google then says here:
Cloud Client Libraries are the recommended option for accessing Cloud APIs programmatically, where available
However, these newer cloud Libraries don't seem to offer OAuth2 authentication for access on behalf of another user (not myself).
For example, I'd like to use the Google Analytics Admin API.
I visit the Google Analytics Admin Cloud Client library and the documentation tells me to authenticate by downloading the JSON file from my credential area (This works only if I access my own services but NOT to make API calls on behalf of a given user)
// Instantiates a client using default credentials.
// TODO(developer): uncomment and use the following line in order to
// manually set the path to the service account JSON file instead of
// using the value from the GOOGLE_APPLICATION_CREDENTIALS environment
// variable.
// const analyticsAdminClient = new analyticsAdmin.AnalyticsAdminServiceClient(
// {keyFilename: "your_key_json_file_path"});
const analyticsAdminClient = new analyticsAdmin.AnalyticsAdminServiceClient();
// Calls listAccounts() method of the Google Analytics Admin API and prints
// the response for each account.
const [accounts] = await analyticsAdminClient.listAccounts();
So then I visit the older Google API Client library for Analytics Admin.
It supports Oauth2 access_tokens ... but first thing it says:
Note: Google provides multiple libraries for this service. This library is in maintenance mode, and will continue to be made available for users who have existing applications. If you're building a new application, or modernizing a legacy application, please use @google-analytics/admin instead. The @google-analytics/admin library is faster, easier to use, and better maintained.
I want the newer better libraries, but do they support Oauth2 on behalf of other users?
I know that I can acquire oAuth2 access_tokens with the Google Auth Library. But I don't know how to use these tokens then to authorize with the newer cloud libraries.
They do offer oauth2 they just don't offer a sample for it, but I do.