Facebook 身份验证与 Facebook 应用程序错误

发布于 2024-11-09 12:34:37 字数 1494 浏览 0 评论 0原文

我按照此处的说明进行操作,当 Facebook 应用程序运行时,它工作正常。未安装。当安装官方Facebook应用程序时,调用authorize后不会调用回调,并且我没有取回令牌。安装应用程序后,会出现闪亮的登录屏幕(来自 Facebook 应用程序),如果没有安装,则会出现网络视图。 我搜索了很多,但每个教程都说我应该使用我链接的页面中的示例。我缺少什么?

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月野兔 2024-11-16 12:34:37

您需要重写 Activity 中的 onActivityResult 方法:

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

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);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文