【问题标题】:Problem with showing a Facebook profile image in an ImageView在 ImageView 中显示 Facebook 个人资料图像的问题
【发布时间】:2021-08-05 04:55:53
【问题描述】:

一旦用户登录,我试图在 ImageView 中使用 Glide 显示 Facebook 个人资料图像,问题是 Glide 仅从 Facebook 加载默认图像,我尝试了不同的方式,但默认情况下它总是加载相同的图像.

This is the image that Glide shows

这是我的代码:

onCreate 方法:

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_menu, container, false);

    if (AccessToken.getCurrentAccessToken() == null){
        goLoginScreen();
    }else {
        Profile profile = Profile.getCurrentProfile();
        if (profile != null){
            displayProfileInfo(profile);
        }else{
            Profile.fetchProfileForCurrentAccessToken();
        }
    }
    return view;
}

displayProfileInfo 方法:

private void displayProfileInfo(Profile profile){
    String name = profile.getName();
    String photoUrl = profile.getProfilePictureUri(100,100).toString();

    txtviewUname.setText(name);
    Glide.with(getActivity()).load(photoUrl).into(profileImage);
}

【问题讨论】:

  • 默认图片是什么意思?你关注API Docs了吗?
  • 你能给我们看一个“来自 Facebook 的默认图片”的例子吗?请回复@AlexMamo
  • 收到url后在logcat中打印photoUrl变量数据,然后点击浏览器
  • @AlexMamo 嗨,我用截图更新了问题,这就是我所说的默认图像
  • 嗨,我用屏幕截图更新了问题,当我将网址放入浏览器时,默认情况下它会显示相同的图像。所以问题是图片网址?我怎样才能得到正确的网址? @MuhammadAsad

标签: java android firebase android-studio


【解决方案1】:

根据您的评论:

当我将 URL 放入浏览器时,默认情况下它会显示相同的图像。

这意味着存在于FirebaseUser 类中的getPhotoUrl() 方法返回一个指向有效照片的URL。但是,当用户决定将任何照片添加到个人资料时,Facebook 会自动添加该照片。因此,如果用户没有任何照片,则将始终显示默认照片。因此,当您尝试读取与此类帐户关联的照片时,将显示默认照片。

【讨论】:

  • 嗨,Alex,我通过更新 Facebook sdk 并使用 Profile 类的方法解决了这个问题,当我使用 FirebaseUser 类的 getPhotoUrl() 方法时,它返回默认图像,即使用户有个人资料图像。感谢您的帮助
  • 嘿,安德烈。很高兴听到你解决了它。
【解决方案2】:

使用上下文,例如

getContext()

requireContext()

,如果它只在 Activity 中使用

这个

Glide 使用上下文

【讨论】:

  • 你好,之前我已经用getContext()试过了,还是不行,看来问题出在facebook图片的url
猜你喜欢
  • 2014-05-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-09-18
  • 2019-11-18
  • 1970-01-01
  • 2012-08-19
相关资源
最近更新 更多