Skip to content

Instantly share code, notes, and snippets.

@jayrambhia
Last active August 29, 2015 14:08
Show Gist options
  • Save jayrambhia/e5161d5a0b027c1d2776 to your computer and use it in GitHub Desktop.
Save jayrambhia/e5161d5a0b027c1d2776 to your computer and use it in GitHub Desktop.
final String URL = "http://graph.facebook.com/" + fbID + "/picture?type=large";
// Use a thread because networking operations can't be
// carried out in UI thread.
new Thread(new Runnable() {
@Override
public void run() {
Bitmap bitmap = BitmapFatory.decodeStream(HttpRequest(URL));
// save bitmap
}
}).start();
public static InputStream HttpRequest(String strUrl) {
HttpResponse response = null;
try {
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpGet request = new HttpGet();
request.setURI(new URI(strUrl));
response = httpClient.execute(request);
HttpEntity entity = response.getEntity();
return entity.getContent();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (URISyntaxException e) {
e.printStackTrace();
} catch (NullPointerException e) {
e.printStackTrace();
}
return null;
}
public class SignUpActivity extends Activity {
private String nameString;
private String emailString;
private String fbID;
// some stuff
// onCreate, onPause, set layout, create buttons, etc
private void signUpUsingFacebook() {
Toast.makeText(this, "Connecting to facebook", Toast.LENGTH_LONG).show();
Session.openActiveSession(this, true, Arrays.asList("email", "user_birthday"), new Session.StatusCallback() {
@Override
public void call(Session session, SessionState state,
Exception exception) {
if (session.isOpened()) {
Request.newMeRequest(session, new Request.GraphUserCallback() {
@Override
public void onCompleted(GraphUser user,
Response response) {
if (user == null) {
Toast.makeText(SignUpActivity.this, "Unable to connect to Facebook", Toast.LENGTH_SHORT).show();
return;
}
nameString = user.getFirstName() + " " + user.getLastName();
emailString = (String) user.getProperty("email");
fbID = user.getId();
}
}).executeAsync();
}
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment