Java 类com.facebook.android.Facebook 实例源码

项目:SevenWonders    文件:LoginAndGetPermissions.java   
@Override
public void onCreate(Bundle savedInstanceState) {
    //ALog.m();

    super.onCreate(savedInstanceState);

    mFacebook = new Facebook();

       if ( mFacebook.isSessionValid() ) {
        //ALog.i("Already have a saved Facebook session, skipping authorization.");

        setResult(RESULT_OK);
        finish();
        return;
       }        

       mFacebook.authorize(this, FacebookConfig.getAppId(), PERMISSIONS, new LoginDialogListener());
    //setContentView(R.layout.facebook);
   }
项目:foursquared    文件:AddFriendsByUserInputActivity.java   
private void startFacebookWebViewActivity() {
    Intent intent = new Intent(this, FacebookWebViewActivity.class);
    intent.putExtra(FacebookWebViewActivity.INTENT_EXTRA_ACTION, Facebook.LOGIN);
    intent.putExtra(FacebookWebViewActivity.INTENT_EXTRA_KEY_APP_ID, 
            getResources().getString(R.string.facebook_api_key));
    intent.putExtra(FacebookWebViewActivity.INTENT_EXTRA_KEY_PERMISSIONS, 
            new String[] {}); //{"publish_stream", "read_stream", "offline_access"});
    intent.putExtra(FacebookWebViewActivity.INTENT_EXTRA_KEY_DEBUG, false);
    intent.putExtra(FacebookWebViewActivity.INTENT_EXTRA_KEY_CLEAR_COOKIES, true);
    startActivityForResult(intent, ACTIVITY_RESULT_FACEBOOK_WEBVIEW_ACTIVITY);
}
项目:foursquared    文件:AddFriendsByUserInputActivity.java   
/**
 * Listen for FacebookWebViewActivity finishing, inspect success/failure and returned
 * request parameters.
 */
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == ACTIVITY_RESULT_FACEBOOK_WEBVIEW_ACTIVITY) {
        // If RESULT_OK, means the request was attempted, but we still have to check the return status.
        if (resultCode == RESULT_OK) {
            // Check return status.
            if (data.getBooleanExtra(FacebookWebViewActivity.INTENT_RESULT_KEY_RESULT_STATUS, false)) {

                // If ok, the result bundle will contain all data from the webview.
                Bundle bundle = data.getBundleExtra(FacebookWebViewActivity.INTENT_RESULT_KEY_RESULT_BUNDLE);

                // We can switch on the action here, the activity echoes it back to us for convenience.
                String suppliedAction = data.getStringExtra(FacebookWebViewActivity.INTENT_RESULT_KEY_SUPPLIED_ACTION);
                if (suppliedAction.equals(Facebook.LOGIN)) {
                    // We can now start a task to fetch foursquare friends using their facebook id.
                    mStateHolder.startTaskFindFriends(
                            AddFriendsByUserInputActivity.this, bundle.getString(Facebook.TOKEN));
                }
            } else {
                // Error running the operation, report to user perhaps.
                String error = data.getStringExtra(FacebookWebViewActivity.INTENT_RESULT_KEY_ERROR);
                Log.e(TAG, error);
                Toast.makeText(this, error, Toast.LENGTH_LONG).show();
                finish();
            }
        } else {
            // If the user cancelled enterting their facebook credentials, exit here too.
            finish();
        }
    }
}
项目:Socialite    文件:SharedPreferencesCredentialStore.java   
public static void clearFacebookCredentials(Facebook facebook, Context context) {   
    if(facebook.isSessionValid())
        facebook.getSession().close();
    Editor editor = context.getSharedPreferences(FACEBOOK_KEY, Context.MODE_PRIVATE).edit();
    editor.remove(FACEBOOK_TOKEN);
    editor.commit();
}
项目:Socialite    文件:FacebookConnector.java   
public FacebookConnector(String appId, String[] permissions, SocialActivity socialActivity) {

        this.facebook = new Facebook(appId);
        SharedPreferencesCredentialStore.restoreFacebookSession(facebook, socialActivity.getApplicationContext());
        this.permissions=permissions;
        this.mHandler = new Handler();
        this.activity = socialActivity;
        socialActivity.registerSocialConnector(this);

    }
项目:Socialite    文件:FacebookConnector.java   
public FacebookConnector(String appId, String[] permissions, SocialSliderActivity socialActivity) {

        this.facebook = new Facebook(appId);
        SharedPreferencesCredentialStore.restoreFacebookSession(facebook, socialActivity.getApplicationContext());
        this.permissions=permissions;
        this.mHandler = new Handler();
        this.activity = socialActivity;
        socialActivity.registerSocialConnector(this);

    }
项目:kaorisan    文件:ShareFacebookActivity.java   
public void shareFacebook(){
    facebook = new Facebook("1418005058449444");
    restoreCredentials(facebook);
    messageToPost = "Hello Everyone.";
    if (!facebook.isSessionValid()) {
        loginAndPostToWall();
    } else {
        postToWall(messageToPost);
    }
}
项目:SevenWonders    文件:SessionStore.java   
public static boolean save(Facebook session, Context context) {
    Editor editor =
        context.getSharedPreferences(KEY, Context.MODE_PRIVATE).edit();
    editor.putString(TOKEN, session.getAccessToken());
    editor.putLong(EXPIRES, session.getAccessExpires());
    return editor.commit();
}
项目:SevenWonders    文件:SessionStore.java   
public static boolean restore(Facebook session, Context context) {
    SharedPreferences savedSession =
        context.getSharedPreferences(KEY, Context.MODE_PRIVATE);
    session.setAccessToken(savedSession.getString(TOKEN, null));
    session.setAccessExpires(savedSession.getLong(EXPIRES, 0));
    return session.isSessionValid();
}
项目:SevenWonders    文件:FacebookApplicationPost.java   
private void makeWallPost() {
    //ALog.m();

    Facebook facebook = new Facebook();      
    SessionStore.restore(facebook, this);

    //ALog.i("stream.publish parameters: ", mParams);
    facebook.dialog(FacebookApplicationPost.this, "stream.publish", mParams, 
        new WallPostDialogListener());  
}
项目:haxsync    文件:FacebookUtil.java   
@Override
public void onComplete(Bundle values) {
    //Log.i("got values", values.toString());
    accessToken = values.getString(Facebook.TOKEN);
    // TODO Auto-generated method stub

}
项目:facebook-android-sdk    文件:Tests.java   
public boolean testPublicApi() {
    Facebook fb = new Facebook(APP_ID);
    try {
        Log.d("Tests", "Testing standard API call");
        JSONObject response = Util.parseJson(fb.request("4"));
        if (!response.getString("name").equals("Mark Zuckerberg")) {
            return false;
        }

        Log.d("Tests", "Testing an API call with a specific method");
        response = Util.parseJson(
                fb.request("soneff", new Bundle(), "GET"));
        if (!response.getString("name").equals("Steven Soneff")) {
            return false;
        }

        Log.d("Tests", "Testing a public search query");
        Bundle params = new Bundle();
        params.putString("q", "facebook");
        response = Util.parseJson(fb.request("search", params));
        if (response.getJSONArray("data").length() == 0) return false;

        Log.d("Tests", "Public API Tests passed"); 
        return true;
    } catch (Throwable e) {
        e.printStackTrace();
        return false;
    }
}
项目:Socialite    文件:SharedPreferencesCredentialStore.java   
public static boolean restoreFacebookSession(Facebook facebook, Context context) {  
    SharedPreferences savedSession = context.getSharedPreferences(FACEBOOK_KEY, Context.MODE_PRIVATE);
    facebook.setAccessToken(savedSession.getString(FACEBOOK_TOKEN, null));
    facebook.setAccessExpires(savedSession.getLong(EXPIRES, 0));
    return facebook.isSessionValid();
}
项目:Socialite    文件:SharedPreferencesCredentialStore.java   
public static boolean saveFacebookToken(Facebook session, Context context) {
    Editor editor = context.getSharedPreferences(FACEBOOK_KEY, Context.MODE_PRIVATE).edit();
    editor.putString(FACEBOOK_TOKEN, session.getAccessToken());
    editor.putLong(EXPIRES, session.getAccessExpires());
    return editor.commit();
}
项目:Socialite    文件:FacebookConnector.java   
public void forceAuthenticate() {
    facebook.authorize(this.activity, this.permissions, Facebook.FORCE_DIALOG_AUTH,new LoginDialogListener());
}
项目:Socialite    文件:FacebookConnector.java   
public Facebook getFacebook() {
    return this.facebook;
}
项目:kaorisan    文件:ShareFacebookActivity.java   
public boolean saveCredentials(Facebook facebook) {
    Editor editor = getApplicationContext().getSharedPreferences(KEY, Context.MODE_PRIVATE).edit();
    editor.putString(TOKEN, facebook.getAccessToken());
    editor.putLong(EXPIRES, facebook.getAccessExpires());
    return editor.commit();
}
项目:kaorisan    文件:ShareFacebookActivity.java   
public boolean restoreCredentials(Facebook facebook) {
    SharedPreferences sharedPreferences = getApplicationContext().getSharedPreferences(KEY, Context.MODE_PRIVATE);
    facebook.setAccessToken(sharedPreferences.getString(TOKEN, null));
    facebook.setAccessExpires(sharedPreferences.getLong(EXPIRES, 0));
    return facebook.isSessionValid();
}
项目:kaorisan    文件:ShareFacebookActivity.java   
public void loginAndPostToWall() {
    facebook.authorize(this, PERMISSIONS, Facebook.FORCE_DIALOG_AUTH, new LoginDialogListener());
}
项目:kaorisan    文件:LoginActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login);

    loginActivity = this;
    SQLiteDatabaseAdapter.setContext(this);

    checkGooglePlayServices();

    mPlusClient = new PlusClient.Builder(this, this, this)
    .setVisibleActivities("http://schemas.google.com/AddActivity",
                    "http://schemas.google.com/BuyActivity").setScopes(Scopes.PLUS_LOGIN, Scopes.PLUS_PROFILE).build();

    btnLoginGoogle = (Button) findViewById(R.id.btn_login_google);
    initGoogleButton();

    genKeyHash();
    resource = getResources();

    DebugLog.logd("On create");

    // Create the Facebook Object using the app id.
    if (Utility.mFacebook == null) {
        Utility.mFacebook = new Facebook(APP_ID);
    }
    // Instantiate the asynrunner object for asynchronous api calls.
    if (Utility.mAsyncRunner == null) {
        Utility.mAsyncRunner = new AsyncFacebookRunner(Utility.mFacebook);
    }

    SessionStore.restore(Utility.mFacebook, this);

    SessionEvents.addAuthListener(authenListener);
    SessionEvents.addLogoutListener(logoutListener);

    Settings.addLoggingBehavior(LoggingBehavior.INCLUDE_ACCESS_TOKENS);

    btnLoginFaceBook = (Button) findViewById(R.id.btn_login_facebook);
    initFacebookButton();

    SessionEvents.addAuthListener(mSessionListener);
    SessionEvents.addLogoutListener(mSessionListener);

    if (Utility.mFacebook.isSessionValid() && isLogout == 0 && currentSocial == Social.FACEBOOK) {
        DebugLog.logd("On facebook Create");
        if (Utils.checkInternetConnect(this)) {
            requestGetUserData();
        }
    }

    if (currentSocial == Social.GOOGLE && isLogout == 0) {
        DebugLog.logd("On Google Create");
        mPlusClient.connect();
    }
    checkLogout();

}
项目:haxsync    文件:AuthorizationActivity.java   
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //setContentView(R.layout.main);
    String[] permissions = {"offline_access", "read_stream", "user_events", "friends_events", "friends_status", "user_status", "friends_photos", "user_photos", "friends_about_me", "friends_website", "email", "friends_birthday", "friends_location"};
    FacebookUtil.facebook.authorize(AuthorizationActivity.this, permissions, Facebook.FORCE_DIALOG_AUTH, new DialogListener() {
        @Override
        public void onComplete(Bundle values) {
            FacebookUtil.accessToken = FacebookUtil.facebook.getAccessToken();
            Log.i("Expires", String.valueOf(FacebookUtil.facebook.getAccessExpires()));;
            AccountManager am = AccountManager.get(AuthorizationActivity.this);
            Account account = am.getAccountsByType(AuthorizationActivity.this.getString(R.string.ACCOUNT_TYPE))[0];
            am.setPassword(account, FacebookUtil.facebook.getAccessToken());
            SharedPreferences prefs = AuthorizationActivity.this.getSharedPreferences(AuthorizationActivity.this.getPackageName() + "_preferences", MODE_MULTI_PROCESS);
            SharedPreferences.Editor editor = prefs.edit();
            editor.putInt("permission_level", FacebookUtil.PERMISSION_LEVEL);
            editor.putLong("access_expires", FacebookUtil.facebook.getAccessExpires());
            editor.commit();
            ContentResolver.requestSync(account, ContactsContract.AUTHORITY, new Bundle());
            ContentResolver.requestSync(account, CalendarContract.AUTHORITY, new Bundle());
        //  Log.i(TAG, ContentResolver.);
            //Log.i(TAG, "Calendar :" + ContentResolver.isSyncActive(account, CalendarContract.AUTHORITY));
        //  Log.i(TAG, "Contacts :" + ContentResolver.isSyncActive(account, ContactsContract.AUTHORITY));
            FacebookUtil.isExtendingToken = false;
            AuthorizationActivity.this.finish();
        }

        @Override
        public void onFacebookError(FacebookError error) {
            Log.i(TAG, "fberror");
            AuthorizationActivity.this.finish();
        }

        @Override
        public void onError(DialogError e) {
            Log.i(TAG, "error");
            AuthorizationActivity.this.finish();
        }

        @Override
        public void onCancel() {
            Log.i(TAG, "cancel");
            AuthorizationActivity.this.finish();
        }
    });
}
项目:IPRJapp    文件:Tutorial_1.java   
@SuppressWarnings("deprecation")
@Override
   public void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);        

        if (savedInstanceState != null)

            TutoRes = savedInstanceState.getInt("TutoRes");
        facebook = new Facebook(APP_ID);
        AsyncFacebookRunner   mAsyncRunner = new AsyncFacebookRunner(facebook);
        //loginFacebook();

requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.tutorial_1);
//setLogin();



Session.openActiveSession(this, true, new Session.StatusCallback() {


    @Override
    public void call(final Session session, SessionState state, Exception exception) {
        if (session.isOpened()) {

            Request.newMeRequest(session, new Request.GraphUserCallback() {

                  @Override
                  public void onCompleted(GraphUser user, Response response) {

                      if (user != null) {

                        //welcome = (TextView) findViewById(R.id.welcome);                      
                        Userid = user.getId();
                        User_name= user.getFirstName();


                        }
                  }
                }).executeAsync();
            }
    }
  }); 



final Button  Button = (Button) findViewById(R.id.button1);

Button.setOnClickListener(new View.OnClickListener() {

       @Override
      public void onClick(View v) {

        if(Userid != null && User_name != null){

             Intent intent = new Intent();
             intent.setClass(Tutorial_1.this,Tutorial_2.class);
             db.addUsuario(new Usuario(User_name,Userid));
            startActivity(intent);
             finish();


        }

        else {

            Toast.makeText(getApplicationContext(), "Aguarde o carregamento dos dados do perfil do Facebook", Toast.LENGTH_SHORT).show();

        }

       }

});
   }