0

My profile.getFirstName() is working well but when ever I try profile.getProfilePictureUri(64,64), it is returning null object. I am using loginButton.setReadPermissions("user_friends") this as permission.

EDIT My mistake, profile.getProfilePictureUri not returning null rather it is returning image url of graph api. But i am still not able to set bitmap converted from that url to profile picture.

Code i am using

URL img_value = null;
            try {
                img_value = new URL(""+profile.getProfilePictureUri(64,64));
            } catch (MalformedURLException e) {
                e.printStackTrace();
            }
            Bitmap mIcon1=null;
            try {
                mIcon1 = BitmapFactory.decodeStream(img_value.openConnection().getInputStream());
            } catch (IOException e) {
                e.printStackTrace();
            }
            imageView.setImageBitmap(mIcon1);

Logcat

 at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:272)
            at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:211)
            at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:373)
            at com.android.okhttp.internal.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:323)
            at com.android.okhttp.internal.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:190)
            at com.android.okhttp.internal.http.DelegatingHttpsURLConnection.getInputStream(DelegatingHttpsURLConnection.java:210)
            at com.android.okhttp.internal.http.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:25)
Ajeet
  • 1,540
  • 1
  • 17
  • 30

5 Answers5

3

The Facebook has a view with this function.

<com.facebook.login.widget.ProfilePictureView
        android:id="@+id/profilePicture"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:gravity="center_horizontal"
        android:layout_marginBottom="10dp"
        facebook:com_facebook_preset_size="normal"
        android:layout_gravity="center_horizontal" />

And the unique parameter to pass is the profileId

 profileImage = (ProfilePictureView) findViewById(R.id.profilePicture);
        profileImage.setProfileId(profile.getId());
  • 1
    Yeah it do have. But I want to put profile picture ImageView which is circular in shape. Thank You. – Ajeet Jun 15 '15 at 11:44
  • Maybe this post can help you: http://stackoverflow.com/questions/23464707/display-fb-profile-pic-in-circular-image-view-in-application – Danilo Pereira Jun 16 '15 at 12:57
2

you can use Glide to load your facebook profile picture in a circular shape ImageView:

 if(Profile.getCurrentProfile()!=null){
        Uri url= Profile.getCurrentProfile().getProfilePictureUri(128,128);
           Glide.with(this)
                   .load(url)
                   .thumbnail(Glide.with(this).load(R.drawable.loader))
                   .apply(RequestOptions.circleCropTransform())
                   .into(((ImageView)findViewById(R.id.profile_pic)) );
        }
1

Hi I would like to share a code using that i was able to get the Facebook Profile Picture as follows:

public static Bitmap getFacebookProfilePicture(String userID){
URL imageURL = new URL("https://graph.facebook.com/" + userID + "/picture?type=large");
Bitmap bitmap = BitmapFactory.decodeStream(imageUrl.openConnection().getInputStream());

return bitmap;

}

You are able to get Facebook User id using returned GraphUser Object.

Bitmap bitmap = getFacebookProfilePicture(userId);

Please reply feedback If you have any doubts or Errors while using the code.

Rajan Bhavsar
  • 1,977
  • 11
  • 25
0

I also faced similar problem while using profile.getProfilePictureUri . The URI was coming but the pic was not setting as expected.

My solution is as follows:

I made use of square/picasso library.Link : https://github.com/square/picasso
Its easy to integrate and extremely powerful.

Once incorporated, just make use of the following function as follows:

Picasso.with(context).load(url).into(img);

Hope this helps!

Samurai
  • 3,724
  • 5
  • 27
  • 39
Nishant Jha
  • 129
  • 1
  • 2
  • Actually I already solved it by using profile=Profile.getCurrentProfile().getCurrentProfile() in Asynch task. – Ajeet May 25 '15 at 12:45
-1

You have the Following Two Methods based on which You got the Objetc of Graph User and able to get User id as Follows:

private Session.StatusCallback callback = new Session.StatusCallback() {
    @Override
    public void call(Session session, SessionState state,
            Exception exception) {
        onSessionStateChange(session, state, exception);

    }
};

private void onSessionStateChange(Session session, SessionState state,
        Exception exception) {

    if (session.isOpened()) {
        Log.i("access token", "Access Token" + session.getAccessToken());

        Request.newMeRequest(session, new Request.GraphUserCallback() {
            @Override
            public void onCompleted(GraphUser user, Response response) {
                Log.d("session", "callback ma ayu...");
                if (user != null) {
                    //Here You got the User Id as user.getId(); and used                                       //this id further

                    Log.i("USER BIRTHDAY ", "" + user.getBirthday());
                    updateUI();
                }

            }
        });

    }
}
Rajan Bhavsar
  • 1,977
  • 11
  • 25