路径中的android firebase数据库无效令牌 [英] android firebase database Invalid token in path

查看:65
本文介绍了路径中的android firebase数据库无效令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对电子邮件进行了base64 utf-8编码. 因为它是数据库密钥. 但是,出现以下问题. 我需要帮助.

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

在/user/aW1hZ2VfNTk1NkBuYXZlci5jb20 =处的设置值= 失败:DatabaseError:路径中的令牌无效

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

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

帮帮我...

推荐答案

在我的情况下,编码字符串的末尾有换行符.使用@Arvin在此 answer 中提到的Base64.NO_WRAP作为解决方案.我的编码功能现在看起来像:

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);
}

如果您想要像上面的评论中提到的@BobSnyder一样安全,则仍然可以使用URL_SAFE,并只是修剪String以确保安全.

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.

这篇关于路径中的android firebase数据库无效令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆