【发布时间】:2019-03-06 07:52:25
【问题描述】:
数据库结构
通知结构
成功将我的功能部署到 firebase 后,我在 firebase 功能日志中出现这些错误
1: Function execution took 1724 ms, finished with status: 'error'
2:TypeError: Cannot read property 'uid' of undefined
at exports.sendNotification.functions.firestore.document.onWrite.event
(/user_code/index.js:9:30)
at cloudFunctionNewSignature (/user_code/node_modules/firebase-
functions/lib/cloud-functions.js:105:23)
at cloudFunction (/user_code/node_modules/firebase-functions/lib/cloud-
functions.js:135:20)
at /var/tmp/worker/worker.js:733:24
at process._tickDomainCallback (internal/process/next_tick.js:135:7)
3:{"@type":"type.googleapis.com/google.cloud.audit.AuditLog","status":
{"code":3,"message":"The request has errors"},"authenticationInfo":
{"principalEmail":"info.jap.123@gmail.com"},"requestMetadata"{"callerIp":"39.50.37.100",
索引.js
'use-strict'
const functions = require('firebase-functions');
const admin = require('firebase-admin');
//admin.initializeApp(functions.config().firebase);
exports.sendNotification =
functions.firestore.
document("Users/{uid}/Notification/{nid}").onWrite(event=>
{
const user_id = event.params.uid
const notification_id = event.params.nid;
});
这个类中的通知类我将通知 id 和消息存储到 Firebase-Firestore 中。
private void sendNotification()
{
String number = edTxtDevId.getText().toString();
if (TextUtils.isEmpty(number))
{
edTxtDevId.setError("Please Provide the dev id thank you");
return;
}
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss.SSS");
String time = String.valueOf(cal.getTime());
final String message = "Notification has been sent to this number "+number+" by this number "+user_id+" at time = "+time;
Map<String , Object> notificationMessage = new HashMap<>();
notificationMessage.put("From" , mUserId);
notificationMessage.put("message" , message);
for (int i = 0 ; i < userList.size() ; i++)
{
if (userList.get(i).equals(number))
{
Log.e(TAG, "sendNotification: "+number+" found " +userList.get(i) + " id = "+i);
Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
mFirestore.collection("Users/"+mUserId+"/Notification").add(notificationMessage).addOnSuccessListener(new OnSuccessListener<DocumentReference>() {
@Override
public void onSuccess(DocumentReference documentReference) {
Toast.makeText(MainActivity.this, message, Toast.LENGTH_SHORT).show();
}
});
}
}
}
如果您知道如何解决这些问题,请帮助我 提前谢谢!
【问题讨论】:
-
您是否使用在线控制台进行更改或从您的计算机进行部署?
-
请添加数据库结构以查看您如何存储通知,请回复@。
-
@AlexMamo 请帮我解决这个问题,谢谢你提前
-
@hussainabbas 请添加数据库结构以查看您如何存储通知
-
@AlexMamo 这里是我的数据库用户的结构:{user_id:{Notification:{notification_id:{message,from}}}
标签: javascript android firebase firebase-realtime-database google-cloud-firestore