简体   繁体   中英

Facebook Authentication with Facebook app error

I followed the instructions here , and it works fine, when the Facebook App is not installed. When the official Facebook App is installed, the callback are not called after calling authorize , and I don't get back the token. When the app is installed, the shiny login screen comes up (from the Facebook app), when it's not, the webview. I searched a lot, but every tutorial says I should use the sample from the page I linked. What am I missing?

// 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.");
        }
    });
}

You need to override the onActivityResult method in your Activity:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM