【问题标题】:How do I save user account information to firebase?如何将用户帐户信息保存到 Firebase?
【发布时间】:2019-04-29 22:40:33
【问题描述】:

我为我在 google 项目上的操作创建了一个 Google 登录,我想将帐户信息保存到 firestore 数据库。

我查看了 Google 的示例(示例 here,位于标题“处理数据访问请求”的最底部),但是当您实际尝试将其部署到 firebase 时,你意识到它实际上有无效的语法(或者至少那是对话流内联编辑器所说的......)

这是我尝试部署此代码时的具体错误说明:

The deployment of your Cloud Function failed:
Function load error: Code in file index.js can't be loaded.
Is there a syntax error in your code?
Detailed stack trace: /user_code/index.js:34
app.intent('Get Sign In', async (conv, params, signin) => {
^

SyntaxError: Unexpected token (

有什么建议吗?

感谢您的帮助!

请注意:我只使用教程对 PLUS 说的代码 我在谷歌图书馆和履行行添加了行动(即:

 // Other libraries...
const {
  dialogflow,
  BasicCard,
  Permission,
  Suggestions,
  Carousel,
  SignIn
  } = require('actions-on-google');

// ** code from tutorial / link **     

exports.dialogflowFirebaseFulfillment = functions.https.onRequest(app)

【问题讨论】:

  • 您要部署的节点的 Firebase 配置/版本是什么。我想知道您是否正在部署到 JavaScript 没有但 TypeScript 确实有 async/await 的 Node 6,请参阅:Cloud Functions for Firebase Async Await style
  • 我正在运行/正在运行 Node 6,我解决了问题并将在下面发布。

标签: javascript node.js firebase dialogflow-es actions-on-google


【解决方案1】:

我想出了如何做到这一点,但它与谷歌示例中的操作不同。 如果有人知道如何更轻松地做到这一点或知道我发布的链接中的代码有什么问题(如果有的话..)请告诉我/添加答案!

我决定直接写信给firestore并将它放在“获取登录”功能下(在对话流教程中也提到过)。

这是我用来让用户登录并将信息登录到 Firestore 的功能:

app.intent('Get Signin', (conv, params, signin) => {
    if (signin.status === 'OK') {
        const payload = conv.user.profile.payload;
        conv.ask(`Welcome back ${payload.name}. What can I help you with??`);
        const databaseEntry = conv.user.profile.payload; // Account info, loaded to firestore
        const accountRef = db.collection('Accounts').doc('account_info'); //How you want the info in firestore to appear
        return db.runTransaction(t => {
            t.set(accountRef, {entry: databaseEntry});
            return Promise.resolve('Write complete');
            }).then(doc => {

            }).catch(err => {
                 console.log(`Error writing to Firestore: ${err}`);
     });
    } else {
          conv.close(`To continue, you need to make an account with the app.`);
    }

【讨论】:

    猜你喜欢
    • 2016-12-07
    • 2020-08-10
    • 2011-12-19
    • 1970-01-01
    • 1970-01-01
    • 2012-08-29
    • 1970-01-01
    • 2020-12-11
    • 1970-01-01
    相关资源
    最近更新 更多