Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get user image from Facebook Graph-API

Tags:

I want to show the users profile picture in a list view. When I try to call the graph-api from android to retrieve the image, I always get the following error.

java.io.IOException: Hostname <fbcdn-profile-a.akamaihd.net> was not verified
    at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.getSecureSocket(HttpConnection.java:170)
    at org.apache.harmony.luni.internal.net.www.protocol.https.HttpsURLConnection$HttpsEngine.connect(HttpsURLConnection.java:398)
    at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.sendRequest(HttpURLConnection.java:1224)
    at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.doRequestInternal(HttpURLConnection.java:1558)
    at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.doRequest(HttpURLConnection.java:1551)
    at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1052)
    at org.apache.harmony.luni.internal.net.www.protocol.https.HttpsURLConnection.getInputStream(HttpsURLConnection.java:252)
    at com.facebook.android.Util.openUrl(Util.java:200)
    at com.facebook.android.Facebook.request(Facebook.java:559)

This is the code used by me:

private static void retrieveProfilePicture(String userId) throws MalformedURLException, IOException{
        facebook = FacebookHelper.getInstance();
        Bundle bundle = new Bundle();
        bundle.putString(Facebook.TOKEN, facebook.getAccessToken());
        Object picture = facebook.request("/"+userId+"/picture", bundle, "GET");

When I do the same call in the browser (https://graph.facebook.com//picture?access_token=), then I get the image returned on a url like this https://fbcdn-profile-a.akamaihd.net/...

In which format is the image delivered to me? JSON with a ref to image (url)?

like image 670
mybecks Avatar asked Apr 30 '11 12:04

mybecks


People also ask

Is Facebook graph API deprecated?

API Version Deprecations: As part of Facebook's Graph API and Marketing API, please note the upcoming deprecations: August 3, 2021: Graph API v3. 3 will be deprecated and removed from the platform. August 25, 2021 Marketing API v9.


1 Answers

 ImageView user_picture;
 userpicture=(ImageView)findViewById(R.id.userpicture);
 URL img_value = null;
 img_value = new URL("http://graph.facebook.com/"+id+"/picture?type=large");
 Bitmap mIcon1 = BitmapFactory.decodeStream(img_value.openConnection().getInputStream());
 userpicture.setImageBitmap(mIcon1);

Where ID is one your profile ID.

For Further details check this Reference for Graph API

............................

like image 95
Venky Avatar answered Oct 15 '22 08:10

Venky