Get email from user using Google actions
Asked Answered
S

3

5

I want to recieve the user email using Google Actions as documented here but docs talks about EMAIL permission, but when I read the permission docs here I can't find any EMAIL permission. Any help? How can I receive the user email?

Saleswoman answered 20/5, 2017 at 13:42 Comment(2)
Any luck with this?Hilltop
No way, Google docs really sucksSaleswoman
B
4

Ya, unfortunately the Assistant's SDK doesn't give you the email address. But if you implement account linking (like Ahmed mentioned) and use the Streamlined Flows, then you'll be getting the email provided to you; you just need to use the jsonwebtoken library and you can decode the assertion JWT and grab the email address.

That being said, this happens during "sign in" and token exchange... not during the actual action fulfillment. You'll need to issue a refresh token / access token :S

Belligerency answered 8/6, 2017 at 14:23 Comment(0)
A
7

This is WORKING ,you can do this with account linking.

We have to enable the webhook first and we can see how to enable the webhook in the dialog flow fulfillment docs If we are going to use Google Assistant, then we have to enable the Google Assistant Integration in the integrations first. Then follow the steps mentioned below for the Account Linking in actions on google:-

  1. Go to google cloud console

    • goto API's and Services -> Credentials -> OAuth 2.0 client IDs -> Web client
    • Note the client ID, client secret from there
    • Download JSON - from json note down the project id, auth_uri, token_uri
    • goto Authorised Redirect URIs
    • White list our app's URL, in this URL fixed part is https://oauth-redirect.googleusercontent.com/r/[project-Id] (replace [project-Id] with your project id)
    • Save the changes
  2. Go to Actions on Google(https://console.actions.google.com) -> Account linking setup

  3. In the hosting server logs, we can see the access token value and through access token, we can get the details regarding the email address.

  4. Append the access token to this link "https://www.googleapis.com/oauth2/v1/userinfo?access_token=" and we can get the required details in the resulting json page.
  5. write this code

    accessToken = req.get("originalRequest")
                     .get("data")
                     .get("user")
                     .get("accessToken")
    
    r = requests.get(link) // make get request to link
    
    print("Email Id: " + r.json()["email"])
    print("Name: " + r.json()["name"])
    
Amoebocyte answered 5/4, 2018 at 10:0 Comment(11)
I have a problem in your step 2 for the auth_uri and token_uri. In my JSON, they are already indacated as the ones in 2.5 and when I replace them with the links in 2.2 (googleapis.com) I can't save as it says "Generic URLs are not allowed. You must provide a valid token url specific to your Assistant app." Any clues?Ling
And if I use dialogflow, do I have to create a intent for account logging or will I see the access token in every request?Ling
@RémiC. If you are able to use this Auth url https://accounts.google.com/o/oauth2/auth without any issue, then just go ahead and use this for the auth and token.The whole point of putting a url of googleapis is that , Google Account Linking does not allow google's owned auth server use, but by using some other auth url first and then coming back to https://accounts.google.com/o/oauth2/auth somehow bypasses this issue and you can use the account linking easilyAmoebocyte
You will see the access Token in every request you make to dialogflow. You just need to tick the option which says "Sign in required" in the google assistant integration settings.Amoebocyte
hello again, I did everything up to step 3 but I have a problem when I check the Sign in required: it always answer that my app account is not linked yet... I am logged on my google account in the simulator and I have the google home app for my Google Home Mini but it still doesn't work... do you know anything?Ling
Where it says, your account is not linked yet ,just below there will be a button to link your account. Just click on that and you will be asked from which account do you want to sign in. This is needed just for the first time you deploy your app in Google assistant.Amoebocyte
For some reason, when I press the link my account in the app it goes black and does nothing... I'll check on the Internet if it happened to anyone elseLing
I found nothing about this problem for the app; but I do not have a button to link my account in the simulator as you mentioned. Maybe I have something wrong on my Account linking params?Ling
@RémiC . You won't have a link button in the simulator, it'll only be available on a device. You have to click the button to link your account and it takes some time to link in some cases it may be a dull black screen for that time. If linking doesn't happen, try restarting your device and going to the actions on Google console then overview and then click on test draft in the bottom. Then try linking your account again from the device. Hope this would work :)Amoebocyte
I managed to make it work by clicking on my redirecting link in the DEBUG tab in Actions on Google, the button did not appear... And when I test on my Google Home Mini I just had to check a box in my account paramater so it was easy. Thanks for everything!Ling
I'm glad my post helped you :)Amoebocyte
B
4

Ya, unfortunately the Assistant's SDK doesn't give you the email address. But if you implement account linking (like Ahmed mentioned) and use the Streamlined Flows, then you'll be getting the email provided to you; you just need to use the jsonwebtoken library and you can decode the assertion JWT and grab the email address.

That being said, this happens during "sign in" and token exchange... not during the actual action fulfillment. You'll need to issue a refresh token / access token :S

Belligerency answered 8/6, 2017 at 14:23 Comment(0)
N
1

One approach is to go with account linking. I'm wondering what use cases you might have that won't necessarily work without email or account linking?

Neckline answered 30/5, 2017 at 22:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.