【问题标题】:How to get firebase UID in cloud function when user uninstalls the app?用户卸载应用程序时如何在云功能中获取firebase UID?
【发布时间】:2021-04-22 03:36:06
【问题描述】:

我想通过 firebase 分析触发功能检测应用卸载事件。 Firebase 功能如下图所示

   exports.appUninstall = functions.analytics.event('app_remove').onLog(event => {
    
     const user = event.user;    
     const uid = user.userId; 

     var time = Date.now();      
     var orderKey = 9999999999999 - Date.now();  
         
     var updateMap = {};
     
     updateMap["time"] = time;
     updateMap["orderKey"] = orderKey;
     updateMap["uid"] = uid;
                          
     updateMap['/Uninstalls/'+ uid] = updateMap;
                           
     return admin.database().ref().update(updateMap);
      
     
});

但它显示以下错误。 - 在属性 'uid' 中未定义

Error: Reference.update failed: First argument contains undefined in property 'uid'
at validateFirebaseData (/workspace/node_modules/@firebase/database/dist/index.node.cjs.js:1481:15)
at /workspace/node_modules/@firebase/database/dist/index.node.cjs.js:1601:9
at each (/workspace/node_modules/@firebase/database/dist/index.node.cjs.js:554:13)
at validateFirebaseMergeDataArg (/workspace/node_modules/@firebase/database/dist/index.node.cjs.js:1599:5)
at Reference.update (/workspace/node_modules/@firebase/database/dist/index.node.cjs.js:13838:9)
at exports.appUninstall.functions.analytics.event.onLog.event (/workspace/index.js:1012:36)
at cloudFunction (/workspace/node_modules/firebase-functions/lib/cloud-functions.js:134:23)
at Promise.resolve.then (/layers/google.nodejs.functions-framework/functions-framework/node_modules/@google-cloud/functions-framework/build/src/invoker.js:199:28)
at process._tickCallback (internal/process/next_tick.js:68:7) 

我知道我做错了什么。如何正确操作?

【问题讨论】:

    标签: node.js firebase google-cloud-functions firebase-analytics


    【解决方案1】:

    如果我没记错的话,您需要使用setUserId API 来设置用户 ID。有关如何为每个平台(Android、iOS 等)执行此操作的更多详细信息,请参阅doc。然后,您将能够使用您的问题代码在您的 Cloud Function 中获取它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-02-28
      • 1970-01-01
      • 2018-09-02
      • 2018-04-18
      • 2020-07-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多