Android Can';无法使用Firebase获取FB配置文件图片
我无法在imageView中获取用户的Facebook个人资料图片。我正在努力与毕加索图书馆取得联系。你有办法解决这个问题吗?这是我的密码。提前谢谢 R.string.facebook\u provider\u id=“facebook.com” 错误:Android Can';无法使用Firebase获取FB配置文件图片,android,facebook,firebase,firebase-authentication,facebook-login,Android,Facebook,Firebase,Firebase Authentication,Facebook Login,我无法在imageView中获取用户的Facebook个人资料图片。我正在努力与毕加索图书馆取得联系。你有办法解决这个问题吗?这是我的密码。提前谢谢 R.string.facebook\u provider\u id=“facebook.com” 错误: FATAL EXCEPTION: main Process: com.example.yunus.ototakip, PID: 3045 java.lang.RuntimeException: Unable to start activity
FATAL EXCEPTION: main
Process: com.example.yunus.ototakip, PID: 3045 java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.example.yunus.ototakip/com.example.yunus.ototakip.Hesabim}: java.lang.IllegalArgumentException: Target must not be null.
Hesabim.java
public class Hesabim extends AppCompatActivity {
public FirebaseAuth firebaseAuth;
public FirebaseUser user;
public CircleImageView userImage;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_hesabim);
userImage= (CircleImageView) findViewById(R.id.kullaniciHesapResmi);
firebaseAuth = FirebaseAuth.getInstance();
user = FirebaseAuth.getInstance().getCurrentUser();
if(firebaseAuth.getCurrentUser()==null)
{
finish();
startActivity(new Intent(this,Giris.class));
}
kullaniciMail.setText(firebaseAuth.getCurrentUser().getEmail());
String facebookUserId = "";
user = FirebaseAuth.getInstance().getCurrentUser();
for(UserInfo profile : user.getProviderData()) {
// check if the provider id matches "facebook.com"
if(profile.getProviderId().equals(getString(R.string.facebook_provider_id))) {
facebookUserId = profile.getUid();
}
}
String photoUrl = "https://graph.facebook.com/" + facebookUserId + "/picture?type=medium";
Picasso.with(this).load(photoUrl).into(userImage);
hesabim.xml
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/kullaniciHesapResmi"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/kullanici_pp"
fancy:civ_border_color="@color/colorAccent"
fancy:civ_border_width="2dp" />
我希望您先向facebook申请个人资料图片的许可,bcz未经许可,facebook将不允许您获取任何内容
loginButton.setReadPermissions("public_profile", "email", "user_friends", "user_education_history", "user_hometown", "user_likes", "user_work_history");
或者您也可以使用facebook回调来获取用户配置文件图像,如下图所示
private FacebookCallback<LoginResult> mCallBack = new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(final LoginResult loginResult) {
GraphRequest request = GraphRequest.newMeRequest(
loginResult.getAccessToken(),
new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(
JSONObject object,
GraphResponse response) {
Log.e("response: ", response + "");
try {
String id = object.getString("id").toString();
String email = object.getString("email").toString();
String name = object.getString("name").toString();
String profilePicUrl = "https://graph.facebook.com/" + loginResult.getAccessToken().getUserId() + "/picture?type=large";
Log.d("imageFB", profilePicUrl);
Log.d("FB_ID:", id);
checkFBLogin(id, email, name, profilePicUrl);
} catch (Exception e) {
e.printStackTrace();
}
finish();
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "id,name,email,gender,birthday,friends,likes,hometown,education,work");
request.setParameters(parameters);
request.executeAsync();
}
private facebook callback mCallBack=new facebook callback(){
@凌驾
成功时公开作废(最终登录结果登录结果){
GraphRequest请求=GraphRequest.newmereRequest(
loginResult.getAccessToken(),
新建GraphRequest.GraphJSONObjectCallback(){
@凌驾
公共空间未完成(
JSONObject对象,
GraphResponse(反应){
Log.e(“响应:,响应+”);
试一试{
字符串id=object.getString(“id”).toString();
字符串email=object.getString(“电子邮件”).toString();
字符串名称=object.getString(“名称”).toString();
字符串profilePicUrl=”https://graph.facebook.com/“+loginResult.getAccessToken().getUserId()+”/picture?type=large”;
Log.d(“imageFB”,profilePicUrl);
Log.d(“FB_ID:,ID”);
checkFBLogin(id、电子邮件、姓名、profilePicUrl);
}捕获(例外e){
e、 printStackTrace();
}
完成();
}
});
Bundle参数=新Bundle();
参数.putString(“字段”、“id、姓名、电子邮件、性别、生日、朋友、爱好、家乡、教育、工作”);
请求。设置参数(参数);
request.executeAsync();
}
使用这个非常简单的解决方案,您可以获得高分辨率的个人资料图片:
如果遵循Firebase示例,请在updateUI方法内部使用:
photoUrl = user.getPhotoUrl(); //here you get the picture
photoUrlstr = photoUrl.toString(); //here you store the link to quality
photoUrlstr = photoUrlstr + "?height=500"; //adjust quality
Glide.with(this).load(photoUrlstr).into(IVperfil); //put it in Imageview
希望有帮助,因为这是太多的简单代码。我的代码包括loginButton.setReadPermissions(“电子邮件”、“公共配置文件”);行。我应该在我的登录活动中使用您的代码还是在登录活动后打开的活动中使用您的代码?在登录活动中使用此代码。并将图像传递给下一个活动。是的..它是我的..使用此功能我将fb数据传递给服务器。我的代码在没有此功能的情况下工作,但现在我在尝试获取Facebook的个人资料图片时遇到问题,如下图所示: