У меня есть система уведомлений.Я не сохраняю данные непосредственно под пользовательским узлом.
это мое дерево данных firebase:
+notifall:
+-L-oplpmjınnlın:
+type:"followedyou"
+from:"{followerUid}"
+users:
+{userUid}:
+notif:
+-L-oplpmjınnlın:"true"
Когда я хочу показать уведомление в программе recyclerview, я делаю так:
FirebaseDatabase.getInstance().getReference().child("notifall").child(list.get(position)).addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
if(dataSnapshot.exists()){
holder.uid=dataSnapshot.child("from").getValue().toString();
FirebaseDatabase.getInstance().getReference().child("users").child(holder.uid).child("block").child(FirebaseAuth.getInstance().getUid()).addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot1) {
FirebaseDatabase.getInstance().getReference().child("users").child(dataSnapshot.child("from").getValue().toString()).child("about").addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot1) {
Glide.with(context).load(dataSnapshot1.child("profilephotourl").getValue().toString()).into(holder.profilephoto);
holder.name.setText(dataSnapshot1.child("namesurname").getValue().toString());
if(dataSnapshot.child("type").getValue().toString().equals("followedyou")){
holder.desc.setText(activity.getString(R.string.followedyou));
Drawable drawable = activity.getResources().getDrawable(R.drawable.ic_newfollow);
holder.notiftype.setImageDrawable(drawable);
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
Теперь я хочу реализовать уведомления с помощью Firebase Cloud Messaging.Я посмотрел пример кода в github.
Это мой код, но он дает мне неожиданную ошибку токена, когда я пытаюсь развернуть функции:
exports.sendFollowerNotification = functions.database.ref('/users/{followedUid}/notifs/{notifId}')
.onWrite(async (change, context) => {
const notifId = context.params.notifId;
const followedUid = context.params.followedUid;
var db = admin.database();
db.ref("notifall").child(notifId).once('value',function(snapshot){
if(snapshot.exists()){
const type = snapshot.child("type").val();
if(type==="followedyou"){
const followeruid = snapshot.child("from").val();
db.ref("users").child(followeruid).child("about").once('value',function(snapshot1){
if(snapshot1.exists()){
const name=snapshot1.child("namesurname").val();
const ppurl=snapshot1.child("profilephotourl")
db.ref("users").child(followedUid).child("token").once('value',function(snapshot3){
if(snapshot3.exists()){
const token=snapshot3.val();
var message = {
data: {
title: 'followedyou',
from: followeruid,
name: name,
image: ppurl
},
token: token
};
admin.messaging().send(message)
.then((response) => {
})
.catch((error) => {
});
}
});
}
});
}
}
});
});
Как я могу это исправить?
Стоит упомянуть.Я действительно новичок в javascript.
Редактировать: Ошибки
Обновление: даже когда я использую официальный пример кода из github (https://github.com/firebase/functions-samples/blob/Node-8/fcm-notifications/functions/index.js), я все еще выдаю ту же ошибку.
"Неожиданный токен =>"
Полный журнал ошибок:
0 info it worked if it ends with ok
1 verbose cli [ '/usr/bin/node',
1 verbose cli '/usr/bin/npm',
1 verbose cli '--prefix',
1 verbose cli '/home/ali/Documents/ShareFunction/functions',
1 verbose cli 'run',
1 verbose cli 'lint' ]
2 info using npm@6.4.1
3 info using node@v11.1.0
4 verbose run-script [ 'prelint', 'lint', 'postlint' ]
5 info lifecycle functions@~prelint: functions@
6 info lifecycle functions@~lint: functions@
7 verbose lifecycle functions@~lint: unsafe-perm in lifecycle true
8 verbose lifecycle functions@~lint: PATH: /usr/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/home/ali/Documents/ShareFunction/functions/node_modules/.bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/var/lib/snapd/snap/bin
9 verbose lifecycle functions@~lint: CWD: /home/ali/Documents/ShareFunction/functions
10 silly lifecycle functions@~lint: Args: [ '-c', 'eslint .' ]
11 silly lifecycle functions@~lint: Returned: code: 1 signal: null
12 info lifecycle functions@~lint: Failed to exec lint script
13 verbose stack Error: functions@ lint: `eslint .`
13 verbose stack Exit status 1
13 verbose stack at EventEmitter.<anonymous> (/usr/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:301:16)
13 verbose stack at EventEmitter.emit (events.js:182:13)
13 verbose stack at ChildProcess.<anonymous> (/usr/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack at ChildProcess.emit (events.js:182:13)
13 verbose stack at maybeClose (internal/child_process.js:970:16)
13 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:257:5)
14 verbose pkgid functions@
15 verbose cwd /home/ali/Documents/ShareFunction
16 verbose Linux 4.19.2-1-MANJARO
17 verbose argv "/usr/bin/node" "/usr/bin/npm" "--prefix" "/home/ali/Documents/ShareFunction/functions" "run" "lint"
18 verbose node v11.1.0
19 verbose npm v6.4.1
20 error code ELIFECYCLE
21 error errno 1
22 error functions@ lint: `eslint .`
22 error Exit status 1
23 error Failed at the functions@ lint script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]