daily pastebin goal
47%
SHARE
TWEET

Untitled

a guest Jan 20th, 2019 130 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. try {
  2.         Log.d(TAG, "postToFaceBook()");
  3.         if (facebook == null) {
  4.             facebook = new Facebook(API);
  5.             String access_token = prefs.getFBAccesTocken();
  6.  
  7.             long expires = prefs.getFBExpiry();
  8.             if (access_token != null) {
  9.                 facebook.setAccessToken(access_token);
  10.             }
  11.             if (expires != 0) {
  12.                 facebook.setAccessExpires(expires);
  13.             }
  14.         }
  15.  
  16.         if (facebook.isSessionValid()) {
  17.             Log.d(TAG, "Session is valid");
  18.             facebook.extendAccessTokenIfNeeded(this, null);
  19.             postToFacebook();
  20.         } else {
  21.             Log.d(TAG, "not valid");
  22.             // Using SSO OAuth
  23.             // facebook.authorize(this, new String[] { "publish_stream"
  24.             // },new LoginDialogListener());
  25.  
  26.             // Not using SSO
  27.             facebook.authorize(this, new String[] { "publish_stream" },
  28.                     Facebook.FORCE_DIALOG_AUTH, new LoginDialogListener());
  29.         }
  30.     } catch (NullPointerException e) {
  31.         Log.e(TAG, "An error occurd trying to open facebook app");
  32.    
  33. public class LoginDialogListener extends BaseDialogListener {
  34.  
  35.     @Override
  36.     public void onComplete(Bundle values) {
  37.         Log.d(TAG, "Login response recieved");
  38.         prefs.saveToken(facebook.getAccessToken());
  39.         prefs.saveExpiry(facebook.getAccessExpires());
  40.         facebook.extendAccessTokenIfNeeded(MyActivity.this, null);
  41.         Log.d(TAG, "Logged in ");
  42.         postToFacebook();
  43.     }
  44.  
  45. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top