Gau*_*rma 19 android facebook-authentication firebase firebase-authentication
我正在使用FirebaseAuth通过FB登录用户.这是代码:
private FirebaseAuth mAuth;
private FirebaseAuth.AuthStateListener mAuthListener;
private CallbackManager mCallbackManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FacebookSdk.sdkInitialize(getApplicationContext());
// Initialize Firebase Auth
mAuth = FirebaseAuth.getInstance();
mAuthListener = firebaseAuth -> {
FirebaseUser user = firebaseAuth.getCurrentUser();
if (user != null) {
// User is signed in
Log.d(TAG, "onAuthStateChanged:signed_in:" + user.getUid());
} else {
// User is signed out
Log.d(TAG, "onAuthStateChanged:signed_out");
}
if (user != null) {
Log.d(TAG, "User details : " + user.getDisplayName() + user.getEmail() + "\n" + user.getPhotoUrl() + "\n"
+ user.getUid() + "\n" + user.getToken(true) + "\n" + user.getProviderId());
}
};
}
Run Code Online (Sandbox Code Playgroud)
问题是我从使用中获得的照片user.getPhotoUrl()非常小.我需要一个更大的图像,但无法找到一种方法.任何帮助将受到高度赞赏.我已经通过firebase登录尝试了这个
获取更大的facebook图像,
但它没有工作,虽然它们是swift我不认为API应该有所不同.
Mat*_*ndt 32
无法从Firebase获取大于提供的个人资料图片getPhotoUrl().但是,只要您拥有用户的Facebook ID,Facebook图表就可以非常简单地获得您想要的任何尺寸的用户个人资料图片.
String facebookUserId = "";
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
ImageView profilePicture = (ImageView) findViewById(R.id.image_profile_picture);
// find the Facebook profile and get the user's id
for(UserInfo profile : user.getProviderData()) {
// check if the provider id matches "facebook.com"
if(FacebookAuthProvider.PROVIDER_ID.equals(profile.getProviderId())) {
facebookUserId = profile.getUid();
}
}
// construct the URL to the profile picture, with a custom height
// alternatively, use '?type=small|medium|large' instead of ?height=
String photoUrl = "https://graph.facebook.com/" + facebookUserId + "/picture?height=500";
// (optional) use Picasso to download and show to image
Picasso.with(this).load(photoUrl).into(profilePicture);
Run Code Online (Sandbox Code Playgroud)
Sor*_*omo 21
两行代码. FirebaseUser user = firebaseAuth.getCurrentUser();
String photoUrl = user.getPhotoUrl().toString();
photoUrl = photoUrl + "?height=500";
Run Code Online (Sandbox Code Playgroud)
简单地追加"?height=500"到最后
Seb*_*que 10
如果有人正在使用FirebaseAuth查找Google帐户.我找到了解决方法.如果您详细说明图片网址:
https://lh4.googleusercontent.com/../.../.../.../s96-c/photo.jpg
/ s96-c /指定图像大小(在这种情况下为96x96),因此您只需要用所需大小替换该值.
String url= FirebaseAuth.getInstance().getCurrentUser().getPhotoUrl();
url = url.replace("/s96-c/","/s300-c/");
Run Code Online (Sandbox Code Playgroud)
您可以分析照片网址,看看是否有其他方法可以更改其尺寸.
正如我在开头所说,这仅适用于Google帐户.检查@Mathias Brandt的答案,获取自定义的Facebook个人资料图片大小.
| 归档时间: |
|
| 查看次数: |
9961 次 |
| 最近记录: |