Using facebook.authorize with the Android SDK does not call onActivityResult

徘徊边缘 提交于 2019-11-30 19:51:34

问题


I'm trying to call the Facebook authorization from my Android activity, but for some reason it never calls the onActivityResult as it should.

I followed the official tutorial, and I even created a very simple application just in order to try this functionality:

public class SimpleFacebookActivity extends Activity {
    private EditText console;
    private Facebook facebook = new Facebook(APP_ID);

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

        this.console = (EditText)super.findViewById(R.id.console);
        this.console.append("Started\n\n");

        String text = Integer.toString(super.getIntent().getFlags() & Intent.FLAG_ACTIVITY_NO_HISTORY);
        this.console.append(text);

        this.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) {
        this.console.append("onActivityResult, request code: " + requestCode + "\n\n");
        super.onActivityResult(requestCode, resultCode, data);
        this.facebook.authorizeCallback(requestCode, resultCode, data);

    }
}

I added a TextEdit widget to which I log, and when I run this application all I get is:

Started

0

I checked to see if the FLAG_ACTIVITY_NO_HISTORY is set since they mention it in the tutorial and in another post I saw here on Stack Overflow, but in my case it's not set and so can't be the problem.

How can I fix this problem?


回答1:


I think this is because you need to add some key to your app in Facebook:

https://developers.facebook.com/docs/mobile/android/build/#sig

But the key is not correctly created when you follow the step-by-step guide, so you got to check for the debugger of the Facebook SDK, to throw you an error telling something like the key you are using is not the same of your app, copy paste and voila!




回答2:


I don't know the Facebook SDK, but it looks to me you should implement these DialogListener methods. Otherwise you don't get any callback of course.



来源:https://stackoverflow.com/questions/8955120/using-facebook-authorize-with-the-android-sdk-does-not-call-onactivityresult

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!