Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/386.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 路径必须是非空字符串,并且可以是';“不包含”&引用&引用#&引用&引用$&引用&引用;[quot;,或";];。你到底是怎么解决这个问题的?_Javascript_Java_Android_Firebase_Firebase Realtime Database - Fatal编程技术网

Javascript 路径必须是非空字符串,并且可以是';“不包含”&引用&引用#&引用&引用$&引用&引用;[quot;,或";];。你到底是怎么解决这个问题的?

Javascript 路径必须是非空字符串,并且可以是';“不包含”&引用&引用#&引用&引用$&引用&引用;[quot;,或";];。你到底是怎么解决这个问题的?,javascript,java,android,firebase,firebase-realtime-database,Javascript,Java,Android,Firebase,Firebase Realtime Database,所以我尝试在不同的设备之间处理通知,这个错误让我发疯,我不知道我哪里做错了。我已经尝试了一切,并尽我最大的努力来解决这个问题,任何帮助都是非常感谢的。非常感谢。 [编辑:我在这里发布了关于另一个错误的问题,问题得到了解决,但导致了这个新错误] 这是我的FirebaseMessagingClass package com.pappu5.navigation; import android.app.NotificationManager; import android.app.PendingInt

所以我尝试在不同的设备之间处理通知,这个错误让我发疯,我不知道我哪里做错了。我已经尝试了一切,并尽我最大的努力来解决这个问题,任何帮助都是非常感谢的。非常感谢。 [编辑:我在这里发布了关于另一个错误的问题,问题得到了解决,但导致了这个新错误]

这是我的FirebaseMessagingClass

package com.pappu5.navigation;

import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.support.v4.app.NotificationCompat;
import com.google.firebase.messaging.RemoteMessage;

public class FirebaseMessaging extends 
com.google.firebase.messaging.FirebaseMessagingService {

private String channelId = "com.pappu5.navigation";

@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);

String notificationTtile = remoteMessage.getNotification().getTitle();
String notificationBody = remoteMessage.getNotification().getBody();
String clickAction = remoteMessage.getNotification().getClickAction();
String from_user_id = remoteMessage.getData().get("from_user_id");


NotificationCompat.Builder mBuilder = new 
NotificationCompat.Builder(this,channelId)
        .setSmallIcon(R.mipmap.ic_launcher)
        .setContentTitle(notificationTtile)
        .setContentText(notificationBody)
        .setPriority(NotificationCompat.PRIORITY_DEFAULT);

int notificationId = (int) System.currentTimeMillis();


Intent intent = new Intent(clickAction);
intent.putExtra("user_id",from_user_id);

intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | 
Intent.FLAG_ACTIVITY_CLEAR_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 
PendingIntent.FLAG_UPDATE_CURRENT);

mBuilder.setContentIntent(pendingIntent);


NotificationManager notificationManager = (NotificationManager) 
getSystemService(NOTIFICATION_SERVICE);

// notificationId is a unique int for each notification that you must define
notificationManager.notify(notificationId, mBuilder.build());

}
这是Firebaseindex.js文件

'use strict'

const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);


exports.sendNotification = 

functions.database.ref('/Notifications/{user_id}/{notification_id}').
onWrite((change, context) => {

const user_id = context.params.user_id;
const notification_id = context.params.notification_id;

console.log('We have a notification to send to : ', 
context.params.user_id);


const fromUser = 
admin.database().ref('/Notifications/'+user_id+'/'+notification_id + 
'/From').once('value');

return fromUser.then(fromUserResult => {

const from_user = fromUserResult.val();
console.log('You have new notification from : ',from_user);

const use_Query = 
admin.database().ref(`/Chat_Profiles/{from_user}/name`).once('value');

const deviceToken = 
admin.database().ref(`/Chat_Profiles/{user_id}/device_token`)
.once('value');

return Promise.all([use_Query,deviceToken]).then(result => {
const userName = result[0].val();
const token_id = result[1].val();

const payload = {
    notification: {
    title: "Friend Request",
    body: userName+" has sent you request",
    icon: "default",
    click_action : "com.pappu5.navigation_TARGET_NOTIFICATION"  
    },
    data : {
        from_user_id: from_user
    }
};
console.log(payload);
    return admin.messaging().sendToDevice(token_id,payload).then(response => {
    return console.log('This was the notification feature');
});
});


});


});

'Chat\u Profiles/'+from\u user+/name'
中,from\u user的
是一个对象。对象的默认
toString
返回
[object object]
,这就是您获得被拒绝的
“/Chat\u Profiles/[object object]/name”的原因。您可能想使用
user\u id
,而不是
from\u user

请整理您的问题。您的标题是一条实际的错误消息吗?如果是这样,请在100多行中指出您在哪里获得它。此外,缩进不正确,这使您的代码更难遵循。是的,这是实际的错误消息(它不适合标题,因此我不得不缩短它)错误:Reference.child失败:第一个参数是无效路径=“/Chat_Profiles/[object object]/name”。路径必须是非空字符串,并且不能包含“.”、“$”、“[”或“]”错误消息是关键信息。标题是指文章的内容;但是你绝对应该把整个错误信息放在文章的正文中,并以某种明确的方式指出它发生在哪一行代码上(因为代码行的编号在你的问题和源代码中可能是不同的)。如果你不努力提问,潜在的回答者就不太愿意努力回答:)我很幸运你的错误消息(在评论中提供)足够详细,可以自己识别位置。谢谢你的回答!嗯,你必须检查这个日志,我从这行const from_user=fromUserResult.val()获取“from user id”;这是一个字符串,但为什么它在下一行之后显示错误?你可以看到我在上面发布的图像,为什么我想要“用户id”?我想要“来自用户”的id,所以你所说的不符合我的需要,我也尝试了你的解决方案,它再次出现错误“值必须是字符串”在“数据。来自用户id”.我正试图从大约2个月的时间里解决这些问题,我想我应该放弃:(最后一句是推测;其余是事实。如果
用户id
不是您想要的,那么使用
控制台.dir
检查您拥有的对象(
来自用户
)然后看看它的哪些属性应该位于路径中。您还没有发布该对象值,所以我只能猜测,但可能类似于来自_user.id的
?问题的关键是,问题没有足够的细节为您提供准确的解决方案,只诊断错误。我是javascript的完全初学者,我已经发布了我的函数在上面的日志屏幕截图中,您可以看到我可以检索“from_user”值,它肯定是一个字符串,但当我传递它时,它是“use_Query”,错误弹出。(如屏幕截图所示,from_user通过使用console.log成功检索)“它肯定是一个字符串”-对我来说,这看起来像个可疑的对象。请尝试
'Chat\u Profiles/'+from\u user.from+'/name'