Get email from user using Google actions

前端 未结 3 1931
一整个雨季
一整个雨季 2020-12-15 13:55

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 EM

相关标签:
3条回答
  • 2020-12-15 14:39

    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?

    0 讨论(0)
  • 2020-12-15 14:45

    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

    0 讨论(0)
  • 2020-12-15 14:50

    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

      • select Grant type = Authorisation code
      • Client info

        • Fill up client id,client secrtet, auth_uri, token_uri
        • Enter any random url as Authorization URL and token_uri such as https://example.com/auth and https://example.com/token
        • Save
        • It will show an error while running on the google assistant, but dont worry
        • Come back to the account linking section in the assistant settings and this time enter correct auth_uri as https://accounts.google.com/o/oauth2/auth and token_uri as https://accounts.google.com/o/oauth2/token

          note that it is some sort of problem in from their side that not allows you to use this url in first hit and will keep saying "Generic URLs are not allowed. You must provide a valid token url specific to your Assistant app." so just give any random url in first hit and save, then comeback again it will allow you these urls :-)

        • Put the scopes as https://www.googleapis.com/auth/userinfo.profile and https://www.googleapis.com/auth/userinfo.email and weare good to go.

        • Save the changes.
    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"])
      
    0 讨论(0)
提交回复
热议问题