Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- FacebookSdk.sdkInitialize(getApplicationContext());
- setContentView(R.layout.activity_main);
- loginButton = (LoginButton) findViewById(R.id.fb_log_in);
- callbackManager = CallbackManager.Factory.create();
- loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
- @Override
- public void onSuccess(LoginResult loginResult) {
- startActivity(new Intent(MainActivity.this, newPageActivity.class));
- String token = AccessToken.getCurrentAccessToken().getToken();
- new FacebookCognitoSync().execute(token);//Cognito integration that works as an async task in the background
- }
- @Override
- public void onCancel() {
- textView.setText("Log in canceled");
- }
- @Override
- public void onError(FacebookException error) {
- }
- });
- }
- @Override
- protected void onActivityResult(int requestCode, int resultCode, Intent data) {
- callbackManager.onActivityResult(requestCode, resultCode, data);
- }
- public class BackgroundCognitoLogin extends AsyncTask<String, Void, String> { //takes fb token and passes it to cognito
- @Override
- protected String doInBackground(String... params)
- {
- String token = params[0];
- Log.d("Background Worker", token);
- CognitoCachingCredentialsProvider credentialsProvider = new CognitoCachingCredentialsProvider(
- getApplicationContext(),
- "us-west-2:4fee8a94-c22c-4bdd-ba86-da488133e4f0", // Identity pool ID
- Regions.US_WEST_2 // Region
- );
- Map<String, String> logins = new HashMap<>();
- logins.put("graph.facebook.com", token);
- credentialsProvider.setLogins(logins);
- // Initialize the Cognito Sync client
- CognitoSyncManager syncClient = new CognitoSyncManager(
- getApplicationContext(),
- Regions.US_WEST_2, // Region
- credentialsProvider);
- credentialsProvider.refresh();
- return "Success";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement