Java 使用google firebase auth时,用户配置文件图像url为空
我正在使用google firebase auth方法对用户进行身份验证我正在使用firebase方法获取用户配置文件信息并将其保存在服务器上。 当我试图在服务器上保存用户图像uri时,它显示空值 下面是我的代码:Java 使用google firebase auth时,用户配置文件图像url为空,java,android,firebase,firebase-authentication,Java,Android,Firebase,Firebase Authentication,我正在使用google firebase auth方法对用户进行身份验证我正在使用firebase方法获取用户配置文件信息并将其保存在服务器上。 当我试图在服务器上保存用户图像uri时,它显示空值 下面是我的代码: FirebaseAuth fAuth = FirebaseAuth.getInstance(); FirebaseUser user = fAuth.getCurrentUser(); if(user != null){ saveData(); } private
FirebaseAuth fAuth = FirebaseAuth.getInstance();
FirebaseUser user = fAuth.getCurrentUser();
if(user != null){
saveData();
}
private void saveData(){
final String uid = user.getUid();
final String email = user.getEmail();
final Uri profileImage = user.getPhotoUrl();
final String name = user.getDisplayName();
RequestQueue requestQueue = Volley.newRequestQueue(BookForm.this);
StringRequest stringRequest = new StringRequest(Request.Method.POST, URL, new Response.Listener<String>(){
@Override
public void onResponse(String response) {
if(response.equals("Successfully inserted")){
Toast.makeText(getApplicationContext(),"Successful",Toast.LENGTH_SHORT.show();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
NetworkResponse status = error.networkResponse;
Toast.makeText(getApplicationContext(),"Error:"+status,Toast.LENGTH_SHORT).show();
}
}){
@Override
protected Map<String, String> getParams() throws AuthFailureError {
HashMap<String,String> map = new HashMap<>();
map.put("userId",uid);
map.put("email",email);
map.put("name",name);
map.put("profileImage", String.valueOf(profileImage));
return map;
}
};
requestQueue.add(stringRequest);
}
有人请让我知道为什么图像uri显示空后保存到服务器。任何帮助都将不胜感激
谢谢不要求身份验证提供商必须为用户提供图像URL。如果提供者没有图像(可能是因为用户从未提供过图像),那么您将得到null。您的代码应该能够处理这种情况 请注意,API文档特别说明: 如果 在包含凭据(AuthCredential)的登录上使用的AuthCredential 此类信息。
我可以请你添加代码片段吗?你是从服务器获取数据的吗?我已经更新了我的帖子和添加的帖子方法。请看一下。好的,我希望你现在从两个方面登录1。Profile_image:req.body.profileImage并检查您是否正在检索它,以及它是否保存在firebase 2中。在android中,从一开始请求检查它实际上是一个链接并且不是空的,然后在这里得到结果。感谢buddy的帮助,Doug的回答解决了我的问题。
router.post('/addData', (req,res) => {
var data = {
User_id: req.body.userId,
Email:req.body.email,
Profile_image:req.body.profileImage,
Name: req.body.name
};
MongoClient.connect(dburl, {useNewUrlParser:true} ,(err,client) => {
if(err){
console.log("Error".red, +err);
}
else{
var collect = client.db('my_db').collection('Example');
collect.insertOne(data, (err,resp) =>{
if(err){
console.log("Error".red, +err);
}
else{
res.send("Successfully inserted");
}
client.close();
});
}
});
});