Skip to content

Instantly share code, notes, and snippets.

@indexer
Created October 14, 2015 11:26
Show Gist options
  • Save indexer/3bf442a6ee75f91fb08c to your computer and use it in GitHub Desktop.
Save indexer/3bf442a6ee75f91fb08c to your computer and use it in GitHub Desktop.
FacebookSdk.sdkInitialize(this);
callbackManager = CallbackManager.Factory.create();
LoginManager.getInstance()
.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override public void onSuccess(final LoginResult loginResult) {
GraphRequest request = GraphRequest.newMeRequest(loginResult.getAccessToken(),
new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject jsonObject, GraphResponse graphResponse) {
L.i(jsonObject.toString());
try {
String id = jsonObject.getString("id");
String access_token = loginResult.getAccessToken().getToken();
String name = jsonObject.getString("name");
String email = jsonObject.getString("email");
String first_name = jsonObject.getString("first_name");
String last_name = jsonObject.getString("last_name");
String gender =
(jsonObject.getString("gender").equalsIgnoreCase("male")) ? "1" : "2";
String picture = jsonObject.getJSONObject("picture")
.getJSONObject("data")
.getString("url");
Subscriber<User> subscriber = new Subscriber<User>() {
@Override public void onNext(User s) {
if (s.profile_image.equalsIgnoreCase("")) s.profile_image = RandomGenerator.getImageURL();
DataUtils.WriteObject(LoginActivity.this, DATA.USER, s);
}
@Override public void onCompleted() {
dialog_login.dismiss();
}
@Override public void onStart() {
dialog_login.show();
}
@Override public void onError(Throwable e) {
e.printStackTrace();
dialog_login.dismiss();
DialogFactory.createGenericErrorDialog(LoginActivity.this, e.getMessage()).show();
}
};
} catch (JSONException e) {
e.printStackTrace();
}
}
});
}
@Override public void onCancel() {
Toast.makeText(LoginActivity.this, "Login Cancel", Toast.LENGTH_LONG).show();
}
@Override public void onError(FacebookException exception) {
Toast.makeText(LoginActivity.this, exception.getMessage(), Toast.LENGTH_LONG).show();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment