Receive email from user with Google actions
Me, unfortunately the SDK helper doesn't give you an email address. But if you implement account binding (as Ahmed mentioned) and use Streamlined Flows, then you will get the email provided to you; you just need to use the jsonwebtoken library and you can decode the JWT assertion and grab the email address.
That being said, it happens during the "login" and token exchange ... not during the actual execution of the action. You will need to issue a refresh / access token token: S
source to share
It's WORKING, you can do it with link.
We have to enable the webhook first, and we can see how to enable the webhook in the dialog flow execution docs. If we are going to use Google Assistant, we must first enable Google Assistant Integration in the integration. Then follow the steps given below to link to account in google actions: -
-
Go to Google Cloud Console -> APIsand Services -> Credentials -> OAuth 2.0 Client IDs -> Web Client -> Note Client ID, Client Secret -> Download JSON - from json mark project id, auth_uri, token_uri -> Authorized Redirect URIs -> White list our app url -> in this fixed part of url https://oauth-redirect.googleusercontent.com/r/ and add project id to url -> Save changes
-
Actions in Google -> Setting up account binding 1. Grant type = Authorization code 2. Client information 1. Fill in client id, client secrtet, auth_uri, token_uri 2. Enter auth uri as https://www.googleapis.com/auth and token_uri as https://www.googleapis.com/token 3. Save and Run 4. It will show an error while running in Google Assistant, but don't worry 5. Go back to the account linking section in Assistant settings and enter auth_uri as https: //accounts.google.com/o/oauth2/auth and token_uri ashttps://accounts.google.com/o/oauth2/token (please note that it will not let you use this url on first hit and will keep saying, "Shared urls are not allowed. You must provide a valid token -a marker specific to your helper app. "So just give an arbitrary url on the first hit and save, then come back again, this will allow you those urls :-)) 6. Place the scopes as https: // www. googleapis.com/auth/userinfo.profile and https://www.googleapis.com/auth/userinfo.email and we should be good. 7. Save your changes.
-
In the hosting server logs, we can see the value of the access token and through the access token, we can get information about the email address.
- Add an access token to this link https://www.googleapis.com/oauth2/v1/userinfo?access_token= "and we can get the required data on the resulting json page.
-
accessToken = req.get("originalRequest").get("data").get("user").get("accessToken")
r = requests.get(link) print("Email Id= " + r.json()["email"]) print("Name= " + r.json()["name"])
source to share
One approach is to go with an account link . I'm wondering what use cases you might have that won't necessarily work without an email or account link?
source to share