Last active
December 19, 2015 11:09
-
-
Save codebutler/5945443 to your computer and use it in GitHub Desktop.
Brainstorming a better Facebook Login API for Android.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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