Skip to content

Instantly share code, notes, and snippets.

@codebutler
Last active December 19, 2015 11:09
Show Gist options
  • Select an option

  • Save codebutler/5945443 to your computer and use it in GitHub Desktop.

Select an option

Save codebutler/5945443 to your computer and use it in GitHub Desktop.
Brainstorming a better Facebook Login API for Android.
public class MyLoginActivity {
private static final int REQUEST_FB = 1;
@Override
public void onCreate(Bundle bundle) {
setContentView(R.layout.activity_login);
findViewById(R.id.facebook_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = Zuck.newLoginIntent(this)
.setReadPermissions("basic_info", "email", "user_likes", "read_friendlists")
.setPublishPermissions("publish_actions")
.build();
startActivityForResult(intent, REQUEST_FB);
}
});
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode != REQUEST_FB) {
return;
}
if (resultCode == RESULT_OK) {
String token = Zuck.getResultAccessToken(data);
// Store token wherever you want, and use it with a sane HTTP library like Retrofit.
} else {
Exception ex = Zuck.getResultError(data);
// Show the error.
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment