Facebook认证与Facebook应用程序错误

时间:2011-05-24 08:47:57

标签: android facebook

我按照here的说明操作,当没有安装Facebook App时,它运行正常。安装官方Facebook应用程序后,调用authorize后不会调用回调,但我没有收回令牌。当安装该应用程序时,会出现闪亮的登录屏幕(来自Facebook应用程序),而不是webview。 我搜索了很多,但是每个教程都说我应该使用我链接的页面中的示例。我错过了什么?

// Facebook connect
public void facebookConnect(View v) {
    /* CocktailflowTest AppID */
    final Facebook facebook = new Facebook("134370943293463");
    facebook.authorize(this, new String[] { "email", "offline_access" }, new DialogListener() {

        @Override
        public void onFacebookError(FacebookError e) {
            e.getMessage();
        }

        @Override
        public void onError(DialogError e) {
            Toast.makeText(LaunchActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onComplete(Bundle values) {
            mFBToken = facebook.getAccessToken();
            getPreferences(MODE_PRIVATE).edit().putString(Prefs.FACEBOOK_TOKEN, mFBToken).commit();
            WebService service = new WebService();
            WebServiceListener l = new LaunchWebserviceListener();
            mDialog = ProgressDialog.show(LaunchActivity.this, "", "Logging in...");
            mDialog.show();
            service.connectWithFacebook(l, mFBToken);
        }

        @Override
        public void onCancel() {
            Log.i(TAG, "Facebook connect was cancelled by user.");
        }
    });
}

1 个答案:

答案 0 :(得分:0)

您需要覆盖Activity中的onActivityResult方法:

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