使用毕加索获取用户的Facebook个人资料照片

时间:2014-05-21 15:14:48

标签: android facebook-graph-api gravatar picasso

我使用Parse作为后端,我试图获取用户个人资料图片并显示它。我不想使用ProfilePictureView,因为即时使用gridview也显示其他imageViews。 正如你所看到的,我也使用了gravater api。

所以问题是:它不会显示个人资料图片,只显示占位符图片(gravatar工作正常并显示),我做错了什么?

   ParseUser user = mUsers.get(position);
            String email;
            if (user.getEmail() == null) { // this is how i check if its a facebook
                                            // user

                ParseUser currentUser = user;
                if (currentUser.get(ParseConstants.KEY_FACEBOOK_DETAILS) != null) {
                    JSONObject userProfile = currentUser
                            .getJSONObject(ParseConstants.KEY_FACEBOOK_DETAILS);
                    try {
                        if (userProfile.getString("facebookId") != null) {
                            String facebookId = userProfile.get("facebookId")
                                    .toString();
                            String facebookName = userProfile.getString("name");
                            holder.nameLabel.setText(facebookName);
                            // holder.userImageView.setProfileId(facebookId);
                            String facebookProfilePicUrl = "http://graph.facebook.com/"
                                    + facebookId + "/picture";

                            Picasso.with(mContext).load(facebookProfilePicUrl)
                                    .placeholder(R.drawable.avatar_empty)
                                    .into(holder.userImageView);
                        }
                    } catch (JSONException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }

                }
            } else {

                email = user.getEmail().toLowerCase(Locale.getDefault());
                if (email.equals("")) {
                    holder.userImageView.setImageResource(R.drawable.avatar_empty);
                } else {
                    String hash = MD5Util.md5Hex(email);
                    String gravatarUrl = "http://www.gravatar.com/avatar/" + hash
                            + "?s=204&d=404";
                    Picasso.with(mContext).load(gravatarUrl)
                            .placeholder(R.drawable.avatar_empty)
                            .into(holder.userImageView);
                }
                holder.nameLabel.setText(user.getUsername());
            }

            GridView gridView = (GridView) parent;
            if (gridView.isItemChecked(position)) {
                holder.checkImageView.setVisibility(View.VISIBLE);
            } else {
                holder.checkImageView.setVisibility(View.INVISIBLE);
            }

            return convertView;

1 个答案:

答案 0 :(得分:19)

从http更改为https。解决了它。