简体   繁体   English

在Android SDK中使用facebook.authorize不会调用onActivityResult

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

I'm trying to call the Facebook authorization from my Android activity, but for some reason it never calls the onActivityResult as it should. 我正在尝试从我的Android活动中调用Facebook授权,但是由于某种原因,它从未按应有的方式调用onActivityResult。

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: 我添加了一个要登录的TextEdit小部件,当我运行此应用程序时,得到的是:

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. 我检查了是否设置了FLAG_ACTIVITY_NO_HISTORY,因为他们在本教程和我在此处的关于Stack Overflow的另一篇文章中提到了FLAG_ACTIVITY_NO_HISTORY,但就我而言,它没有设置,所以不是问题。

How can I fix this problem? 我该如何解决这个问题?

I think this is because you need to add some key to your app in Facebook: 我认为这是因为您需要向Facebook中的应用添加一些密钥:

https://developers.facebook.com/docs/mobile/android/build/#sig 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! 但是当您按照分步指南进行操作时,密钥创建不正确,因此您必须检查Facebook SDK的调试器,并向您抛出错误,告知您所使用的密钥与您使用的密钥不同应用程序,复制粘贴,瞧!

I don't know the Facebook SDK, but it looks to me you should implement these DialogListener methods. 我不知道Facebook SDK,但是在我看来您应该实现这些DialogListener方法。 Otherwise you don't get any callback of course. 否则,您当然不会得到任何回调。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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