Retrieve profile picture using Facebook SDK 3.0 for Android

Giulio Bider picture Giulio Bider · Nov 28, 2012 · Viewed 11.5k times · Source

I've following problem with Facebook SDK 3.0 for Android. I wanna get my (and my friends) profile picture without using their ProfilePictureView widget, so if I use Graph Explorer I see that Json response is:

{
   "data": {
         "url": "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-ash4/372127_1377011138_1538716206_q.jpg", 
         "is_silhouette": false
    }
}

I need that "url" path to download and show the picture, but with the following code:

Request.executeGraphPathRequestAsync(Session.getActiveSession(), 
                                     "me/picture", 
                                      new Request.Callback() {
        @Override
        public void onCompleted(Response response) {
            GraphObject go = response.getGraphObject();
            Log.i("APP_NAME", go.toString());           
        }
});

I obtain this:

GraphObject{graphObjectClass=GraphObject, 
    state={"FACEBOOK_NON_JSON_RESULT":"����\u0000\u0010JFIF\u0000\u0001\u0001\u0000\u0000\u0001\u0000\u0001\u0000\u0000��\u0000"}}

Someone can help me please? Thanks

Cromir

Answer

Jesse Chen picture Jesse Chen · Nov 28, 2012

An easier way would be to execute a GET request to graph.facebook.com/USER_ID/picture so you don't have to first request an URL to the picture, and then execute another GET request to download the picture from the given URL.

Instead of using Request.executeGraphPathRequestAsync, just do a normal GET request to the URL above, e.g. http://graph.facebook.com/4/picture.