Search code examples
androidfacebook-graph-apigravatarpicasso

Getting user's facebook profile picture using picasso


I'm using Parse as a backend, im trying to get the users profile picture and to display it. I dont want to use the ProfilePictureView since im using a gridview that displays other imageViews as well. As you can see i'm also using gravater api.

So the problem is: It will not show the profile picture, only the placeholder picture (the gravatar works fine and displays), what am i doing wrong?

   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;

Solution

  • Changed from http to https. Solved it.