Android:如何使用FirebaseAuth从Facebook获取更大的个人资料图片? [英] Android : How to get larger profile pic from Facebook using FirebaseAuth?
问题描述
我正在使用 FirebaseAuth 通过FB登录用户.这是代码:
I am using FirebaseAuth to login user through FB. Here is the code:
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());
}
};
}
问题是我使用user.getPhotoUrl()
获得的照片很小.我需要更大的图像,无法找到一种方法.任何帮助将不胜感激.
我已经尝试过了
通过Firebase登录获取更大的Facebook图像
但是,尽管它们是快速的,但是它不起作用,我认为API应该不会有所不同.
The issue is that the photo in I get from using user.getPhotoUrl()
is very small. I need a larger image and can't find a way to do that. Any help would be highly appreciated.
I have already tried this
Get larger facebook image through firebase login
but it's not working although they are for swift I don't think the API should differ.
推荐答案
无法从Firebase获取大于getPhotoUrl()
提供的配置文件图片.但是,只要拥有用户的Facebook ID,Facebook图形就可以非常轻松地获取所需大小的用户个人资料图片.
It is not possible to obtain a profile picture from Firebase that is larger than the one provided by getPhotoUrl()
. However, the Facebook graph makes it pretty simple to get a user's profile picture in any size you want, as long as you have the user's Facebook ID.
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);
这篇关于Android:如何使用FirebaseAuth从Facebook获取更大的个人资料图片?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!