使用 Google 个操作从用户那里获取电子邮件
Get email from user using Google actions
我想使用 Google 记录的操作接收用户电子邮件 here but docs talks about EMAIL permission, but when I read the permission docs here 我找不到任何 EMAIL 权限。有什么帮助吗?我怎样才能收到用户邮件?
一种方法是使用 account linking。我想知道您可能有哪些用例在没有电子邮件或帐户链接的情况下不一定有效?
是的,很遗憾,智能助理的 SDK 没有为您提供电子邮件地址。但是,如果您实施帐户链接(如 Ahmed 提到的那样)并使用简化流程,那么您将收到提供给您的电子邮件;你只需要使用 jsonwebtoken 库,你就可以解码断言 JWT 并获取电子邮件地址。
也就是说,这发生在 "sign in" 和代币交换期间……而不是在实际行动执行期间。您需要发出刷新令牌/访问令牌:S
这是有效的,您可以使用帐户 linking 执行此操作。
我们必须先启用webhook,我们可以在对话流程实现文档中看到如何启用webhook
如果我们要使用 Google 助手,那么我们必须先在集成中启用 Google 助手集成。
然后按照下面提到的步骤在 google:-
上进行帐户链接操作
转到google云控制台
- 转到 API 和服务 -> 凭据 -> OAuth 2.0 客户端 ID -> Web 客户端
- 从那里记下客户端 ID、客户端密码
- 下载 JSON - 从 json 记下项目 ID,auth_uri,token_uri
- 转到授权重定向 URI
- 白名单我们应用的 URL,在这个 URL 固定部分是 https://oauth-redirect.googleusercontent.com/r/[project-Id](将 [project-Id] 替换为您的项目 ID)
- 保存更改
转到 Google(https://console.actions.google.com) 上的操作 -> 帐户 link 正在设置
- select授权类型=授权码
客户信息
- 填写client id,client secrtet, auth_uri, token_uri
- 任意输入url作为授权URL和token_uri如https://example.com/auth and https://example.com/token
- 保存
- 在google小助手运行时会报错,不用担心
返回助手设置中的帐户 linking 部分,这次输入正确的 auth_uri 作为 https://accounts.google.com/o/oauth2/auth
和 token_uri 作为 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 :-)
将范围设置为 https://www.googleapis.com/auth/userinfo.profile and https://www.googleapis.com/auth/userinfo.email
我们很高兴去。
- 保存更改。
在托管服务器日志中,我们可以看到访问令牌值,通过访问令牌,我们可以获得有关电子邮件地址的详细信息。
- 将访问令牌附加到此 link“https://www.googleapis.com/oauth2/v1/userinfo?access_token=”,我们可以在生成的 json 页面中获得所需的详细信息。
写这段代码
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"])
我想使用 Google 记录的操作接收用户电子邮件 here but docs talks about EMAIL permission, but when I read the permission docs here 我找不到任何 EMAIL 权限。有什么帮助吗?我怎样才能收到用户邮件?
一种方法是使用 account linking。我想知道您可能有哪些用例在没有电子邮件或帐户链接的情况下不一定有效?
是的,很遗憾,智能助理的 SDK 没有为您提供电子邮件地址。但是,如果您实施帐户链接(如 Ahmed 提到的那样)并使用简化流程,那么您将收到提供给您的电子邮件;你只需要使用 jsonwebtoken 库,你就可以解码断言 JWT 并获取电子邮件地址。
也就是说,这发生在 "sign in" 和代币交换期间……而不是在实际行动执行期间。您需要发出刷新令牌/访问令牌:S
这是有效的,您可以使用帐户 linking 执行此操作。
我们必须先启用webhook,我们可以在对话流程实现文档中看到如何启用webhook 如果我们要使用 Google 助手,那么我们必须先在集成中启用 Google 助手集成。 然后按照下面提到的步骤在 google:-
上进行帐户链接操作转到google云控制台
- 转到 API 和服务 -> 凭据 -> OAuth 2.0 客户端 ID -> Web 客户端
- 从那里记下客户端 ID、客户端密码
- 下载 JSON - 从 json 记下项目 ID,auth_uri,token_uri
- 转到授权重定向 URI
- 白名单我们应用的 URL,在这个 URL 固定部分是 https://oauth-redirect.googleusercontent.com/r/[project-Id](将 [project-Id] 替换为您的项目 ID)
- 保存更改
转到 Google(https://console.actions.google.com) 上的操作 -> 帐户 link 正在设置
- select授权类型=授权码
客户信息
- 填写client id,client secrtet, auth_uri, token_uri
- 任意输入url作为授权URL和token_uri如https://example.com/auth and https://example.com/token
- 保存
- 在google小助手运行时会报错,不用担心
返回助手设置中的帐户 linking 部分,这次输入正确的 auth_uri 作为 https://accounts.google.com/o/oauth2/auth 和 token_uri 作为 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 :-)
将范围设置为 https://www.googleapis.com/auth/userinfo.profile and https://www.googleapis.com/auth/userinfo.email 我们很高兴去。
- 保存更改。
在托管服务器日志中,我们可以看到访问令牌值,通过访问令牌,我们可以获得有关电子邮件地址的详细信息。
- 将访问令牌附加到此 link“https://www.googleapis.com/oauth2/v1/userinfo?access_token=”,我们可以在生成的 json 页面中获得所需的详细信息。
写这段代码
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"])