android firebase database Invalid token in path

青春壹個敷衍的年華 提交于 2020-01-15 06:28:16

问题


I did the base64 utf-8 encoding of the email. Because it is a database key. However, the following problems arise. I need help.

setValue at /user/aW1hZ2VfNTk1NkBuYXZlci5jb20= failed: DatabaseError: Invalid token in path

databaseReference.child("user").child(util.getBase64encode(email)).setValue(userModel)

help me...


回答1:


In my case, the encoded string was having a new line at the end. Using Base64.NO_WRAP as mentioned by @Arvin in this answer worked as a solution. My encoding function now looks like:

public static String encodeToBase64(String strToEncode) {
    byte[] data = null;
    try {
        data = strToEncode.getBytes("UTF-8");
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    return Base64.encodeToString(data, Base64.NO_WRAP);
}

If you're aiming to be safe like what @BobSnyder mentioned in the comments above, you could still use URL_SAFE and just trim the String just to make sure.



来源:https://stackoverflow.com/questions/44160089/android-firebase-database-invalid-token-in-path

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!