Skip to content

Instantly share code, notes, and snippets.

@danilao
Created November 5, 2012 10:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danilao/4016626 to your computer and use it in GitHub Desktop.
Save danilao/4016626 to your computer and use it in GitHub Desktop.
Retrieve final URL from facebook profile image
URL img_value = null;
try {
/* Public image url */
img_value = new URL( "http://graph.facebook.com/" + id + "/picture?type=large" );
/* For caching purposes we need to get an unique url, not the public */
URL img_value_new = new URL("http://graph.facebook.com/" + id + "/picture?type=large&redirect=false" );
/* Open the above url and get the final image profile URL */
HttpClient http = new DefaultHttpClient();
HttpGet httpMethod = new HttpGet();
httpMethod.setURI (new URI(img_value_new .toString()));
HttpResponse response = http. execute(httpMethod );
int responseCode = response. getStatusLine().getStatusCode ();
String responseBody = "";
JSONObject resp = null;
/* If there're any problems we will use public URL */
if(responseCode == 200){
HttpEntity entity = response. getEntity();
if (entity != null){
responseBody = EntityUtils .toString( entity);
resp = new JSONObject( responseBody);
/* We extract the url key from 'data' JSONObject */
img_value = new URL(resp .getJSONObject( "data").getString ("url"));
}
}
/* Bitmap creation */
Bitmap bm = BitmapFactory.decodeStream(img_value);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment