制作Facebook登录按钮Android应用程序页面

时间:2015-07-04 14:01:15

标签: android facebook facebook-login facebook-android-sdk facebook-access-token

我正在制作一个facebook登录页面的Android应用程序,只需使用登录按钮。在我的这个例子中,登录后运行取消方法而不是onSccess。

这是我的代码..

public class MainActivity extends FragmentActivity {
 private TextView info;
 private LoginButton loginButton;
 private CallbackManager callbackManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    FacebookSdk.sdkInitialize(getApplicationContext());
    callbackManager = CallbackManager.Factory.create();
    setContentView(R.layout.activity_main);
   info = (TextView)findViewById(R.id.info);
    loginButton = (LoginButton) findViewById(R.id.login_button);


    loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
        @Override
        public void onSuccess(LoginResult loginResult) {
            AccessToken access_token = AccessToken.getCurrentAccessToken();
            Profile profile = Profile.getCurrentProfile();
            info.setText("welcome"  +profile.getName());

        }

        @Override
        public void onCancel() {
            info.setText("Login attempt canceled.");
        }

        @Override
        public void onError(FacebookException e) {
            info.setText("Login attempt failed.");
        }
    });
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    callbackManager.onActivityResult(requestCode, resultCode, data);


}

}

我该如何解决这个问题?

0 个答案:

没有答案
相关问题