What I want to do
- Let user of my web application share their analytics account with the app.
- Redirect the user to Google authentication which ask them to approve access
- Redirect the user back to the app.
- Generate a report for the user based on his analytics data and data from the app.
- Next time the user will generate their report I don't want to ask them for the logging again.
Where the problem is
I read this Google developers PHP guide. However, the sample code connects to first account that is already shared with the app.
I want to see a piece of code that ask user for their credentials and consequently provides access to their account.
On Stack I've already found this answer Service Applications and Google Analytics API V3: Server-to-server OAuth2 authentication?. However, mentioned APP_EMAIL is not a particular user's e-mail, but developer.gserviceaccount.com identification for the app created in the console.
Also I found this thread Google Analytics Core Reporting API Version 3.0 without client login. It seems that similar topic is solved there, but the important part of code (from my point of view) is missing there.