Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. FacebookSdk.sdkInitialize(getApplicationContext());
  2. setContentView(R.layout.activity_main);
  3. loginButton = (LoginButton) findViewById(R.id.fb_log_in);
  4.  
  5. callbackManager = CallbackManager.Factory.create();
  6. loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
  7. @Override
  8. public void onSuccess(LoginResult loginResult) {
  9. startActivity(new Intent(MainActivity.this, newPageActivity.class));
  10. String token = AccessToken.getCurrentAccessToken().getToken();
  11. new FacebookCognitoSync().execute(token);//Cognito integration that works as an async task in the background
  12.  
  13. }
  14.  
  15. @Override
  16. public void onCancel() {
  17. textView.setText("Log in canceled");
  18. }
  19.  
  20. @Override
  21. public void onError(FacebookException error) {
  22.  
  23. }
  24. });
  25.  
  26.  
  27. }
  28.  
  29. @Override
  30. protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  31. callbackManager.onActivityResult(requestCode, resultCode, data);
  32.  
  33. }
  34.  
  35.  
  36.  
  37.  
  38.  
  39. public class BackgroundCognitoLogin extends AsyncTask<String, Void, String> { //takes fb token and passes it to cognito
  40. @Override
  41. protected String doInBackground(String... params)
  42. {
  43. String token = params[0];
  44. Log.d("Background Worker", token);
  45. CognitoCachingCredentialsProvider credentialsProvider = new CognitoCachingCredentialsProvider(
  46. getApplicationContext(),
  47. "us-west-2:4fee8a94-c22c-4bdd-ba86-da488133e4f0", // Identity pool ID
  48. Regions.US_WEST_2 // Region
  49. );
  50.  
  51.  
  52. Map<String, String> logins = new HashMap<>();
  53. logins.put("graph.facebook.com", token);
  54. credentialsProvider.setLogins(logins);
  55.  
  56. // Initialize the Cognito Sync client
  57. CognitoSyncManager syncClient = new CognitoSyncManager(
  58. getApplicationContext(),
  59. Regions.US_WEST_2, // Region
  60. credentialsProvider);
  61.  
  62. credentialsProvider.refresh();
  63. return "Success";
  64. }
  65.  
  66.  
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement