Post on facebook wall with official facebook app installed

The user of my Android app should be enabled to post a message to his facebook wall.

I used this tutorial as basis for my development: Link to tutorial

So far it is working fine if I have not installed the official facebook app. Thus the code uses the webview and not SSO.

But if I install the Facebook app on the same device following happens: Pressing the "Post to facebook button" in my app opens shortly the facebook app. But it closes immediatley and returns to my app.

The only workaround I have found so far is to use Facebook.FORCE_DIALOG_AUTH:

facebook.authorize(this.activity, this.permissions,Facebook.FORCE_DIALOG_AUTH,new LoginDialogListener());

But this avoids SSO and always webview is used. There are Android apps out there which use the official facebook app and do SSO. But I searched the whole weekend for a solution without getting a clue how they are doing it.

Puting the android key hash to facebook also didnt change anything.


I'm not sure why you went with the tutorial when facebook has an up to date tutorial of their own: http://developers.facebook.com/docs/mobile/android/build/

The official tutorial discuss a lot of issues, including signing it so that it would work in development stage as well. It also of course talks about authentication and the SSO, here's what you need for SSO:

    Facebook facebook = new Facebook("YOUR_APP_ID");

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        facebook.authorize(this, new DialogListener() {
            @Override
            public void onComplete(Bundle values) {}

            @Override
            public void onFacebookError(FacebookError error) {}

            @Override
            public void onError(DialogError e) {}

            @Override
            public void onCancel() {}
        });
    }

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

        facebook.authorizeCallback(requestCode, resultCode, data);
    }

And that's all. Please, read the official tutorial and follow their instructions, it should work well.

链接地址: http://www.djcxy.com/p/49612.html

上一篇: 使用Facebook Android SDK发布文字和图片

下一篇: 在安装官方Facebook应用的Facebook墙上发布