使用 Google Sign In for Google Home 检索电子邮件 [英] Retrieving email with Google Sign In for Google Home

查看:73
本文介绍了使用 Google Sign In for Google Home 检索电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我一直在尝试使用 google home 检索与当前用户关联的电子邮件.

so I've beentrying to retrieve the email associated with the current user using the google home.

很难找到有关该主题的文档,而且从我收集到的信息来看,我应该能够使用 actions-on-google 中的 SignIn 类.这是我的设置.

Documentation is kind of hard to find on the subject and from what I could gather, I should be able to use the SignIn class from actions-on-google. So here is my setup.

DialogFlow -> 创建了两个意图,一个用于启动登录过程,另一个用于跟进该过程.(第二个有事件actions_intent_SIGN_IN".)

DialogFlow -> Created two intent, one to start the sign in process, the other to follow up on the process. (The second one has the event 'actions_intent_SIGN_IN' to it.)

对 google 配置的操作:帐户关联.

Actions on google config : Account Linking.

  • 已选择 - 是,允许用户通过语音注册新帐户
  • 已选择 - 链接类型:Google 登录

并通过将 clientId 添加到我的 dialogflow 配置来将客户端 ID 添加到我的履行层.

And added the client id to my fulfillment layer by adding the clientId to my dialogflow config.

dialogflow({clientId})

因此,当我在模拟器中运行它时(我在我的 google home 设备上得到完全相同的东西),一旦我的登录进入后续意图 (actions_intent_SIGN_IN),我就会收到一个错误,这就是我的登录.状态为错误.从那里,我不知道我能做些什么来获得有关此错误是什么以及如何修复它的更多信息.

So, when I run this in the emulator (I get the same exact thing on my google home device) I get an error as soon as my sign in goes to the followup intent (actions_intent_SIGN_IN), which is that my signin.status is Error. From there, I don't know what I can do to get more information on what this error is and how to fix it.

有什么想法吗?谢谢!

PS:它甚至可能不是可以完成的事情?有没有其他方法可以检索用户的电子邮件?我能够使用 Permission 检索它的名称,但据我所知,没有什么比登录电子邮件更重要了.

PS : It might not even be something that can be done ? Is there any other way to retrieve the email of the user ? I was able to retrieve it's name using Permission, but there's nothing more that SignIn for email as far as I know.

推荐答案

我可以向您展示如何通过 Google 帐户链接获取我的电子邮件地址:您需要准备好 accessToken,然后才能使用此答案中显示的内容.登录完成后,accessToken 在 conv.user.access.token 中.

I can show you how I get my email address with the Google Account linking: You need to have your accessToken available then you could use what is shown in this answer. The accessToken is in conv.user.access.token when the SignIn is completed.

在节点中看起来像这样:

In node this looks like that:

let link = "https://www.googleapis.com/oauth2/v1/userinfo?access_token="+accessToken;
    return new Promise(resolve => {
        request(link,(error, response, body) => {
            if (!error && response.statusCode === 200) {
                let data = JSON.parse(body);
                let name = data.given_name ? data.given_name : '';
                conv.ask(new SimpleResponse({
                    speech: "Hello "+ name + "!",
                    text: "Hello "+ name + "!"
                }));
                resolve();
            } else {
                console.log("Error in request promise: "+error);
                resolve();
            }
        })
    })

你需要的一切都应该在数据对象中.

Everything you need should be in the data object.

希望有帮助.关于您的错误,我不确定,但请尝试执行上面链接中的所有步骤.我在 Dialogflow 中使用了 Sign-In required 框,而不是新的 SignIn,但它的工作方式应该相同.

Hope it helps. About your error, I am not sure but try doing all step in the link above. I'm using the Sign-In required box with Dialogflow and not a new SignIn but it should work the same.

这篇关于使用 Google Sign In for Google Home 检索电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆