简体   繁体   English

如何将用户帐户信息保存到Firebase?

[英]How do I save user account information to firebase?

I've made a Google Log in for my actions on google project, and I want to save the account info to a firestore database. 我已经对自己在Google项目上的操作进行了Google登录,并且想要将帐户信息保存到Firestore数据库中。

I looked at Google's example of how to do this (example here , at the very bottom under heading " Handle Data Access Requests "), but when you actually try to deploy it to firebase, you realize that it's actually has invalid syntax (or at least that's what the dialogflow inline editor is saying.....) 我查看了Google如何执行此操作的示例( 此处的示例,在标题为“ 处理数据访问请求 ”的最底端),但是当您实际尝试将其部署到firebase时,您意识到它实际上具有无效的语法(或位于至少那是dialogflow内联编辑器所说的.....)

Here's what the error says specifically when I try to deploy this code: 当我尝试部署此代码时,该错误具体说明了以下内容:

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 (

Any suggestions? 有什么建议么?

Thanks for the help! 谢谢您的帮助!

Please note: I am using only the code that the tutorial has said to PLUS I added the actions on google library and the fulfillment line (ie: 请注意:我只使用代码的教程,以表示PLUS我说对谷歌图书馆的行动和履行线(即:

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

// ** code from tutorial / link **     

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

I figured out how to do this, however it was a different method than the actions on google example. 我想出了如何做到这一点,但这是不同于google示例操作的方法。 If anyone knows how to do this easier or knows what was wrong with the code in the link I posted (if anything..) please let me know / add an answer! 如果有人知道如何更轻松地完成此操作,或者知道我发布的链接中的代码出了什么问题(如果有的话..), 请告诉我/添加答案!

I decided to just write to firestore directly and put it under a "Get Signin" function (also mentioned in the tutorial for dialogflow). 我决定直接直接写到firestore并将其置于“获取登录”功能下(在dialogflow的教程中也提到了)。

Here is the function I used to get the user to sign in and also log the information into 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.`);
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何保存网站用户的信息? - How do I save information for a user of a website? 如何保存用户信息(userName)firebase new angular 2 - How to save user information (userName) firebase new angular 2 注册帐户后,如何将用户 uid 存储到 firebase 数据库? - How do I store the user uid to firebase database after I register an account? 如何在使用电话号码注册期间将名称和 email 添加到 Firebase 用户帐户? - How do I add name and email to a Firebase user account during signup with phone number? Firebase | JS | 将特定的特殊信息添加到用户帐户 - Firebase | JS | Add particuar particuar information to a user account 通过 expo 在 firebase 中注册帐户的格式以及如何编写代码以在通过应用程序创建新用户时捕获错误 - Format for registration of account in firebase via expo and how do i code my code to catch errors when creating new user via app 如何设置 Firebase 用户的 displayName? - How do I set the displayName of Firebase user? 如何从 Firebase 读取信息并在 React 组件中使用它? - How do I read information from Firebase and use it in a React component? 如何在 Firebase 实时数据库上的功能之间共享信息 - How do I share information between functions on Firebase realtime database 如何在 firebase 中保存用户的关注者? 反应本机 - How can I save user's followers in firebase? React Native
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM