Get email from user using Google actions

泄露秘密 提交于 2019-11-29 00:32:02

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

Jatin

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"])
    

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?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!