简体   繁体   English

android facebook授权:onActivityResult未调用

[英]android facebook authorization: onActivityResult not called

I build an android app connect with facebook, which has a button. 我建立了一个与Facebook连接的Android应用程序,它有一个按钮。 When I click the button, the app will call facebook.authorize to ask permission. 当我单击按钮时,该应用程序将调用facebook.authorize寻求许可。 After return from the ask permission screen, it should call onActivityResult method. 从询问权限屏幕返回后,应调用onActivityResult方法。 But in my case, it never call this method. 但就我而言,它永远不会调用此方法。 I found some similar question but all the solutions don't solve my case. 我发现了一些类似的问题,但是所有解决方案都无法解决我的问题。 Here's my code when user click the button: 这是用户单击按钮时的代码:

facebook.authorize(this, new String[] { "read_friendlists" }, 
                new DialogListener() {
                    public void onComplete(Bundle values) {
                        Log.v("complete", "complete");
                        hideNeedLoginView();
                    }

                    public void onCancel() {
                        Log.v("cancel", "cancel");
                        hideNeedLoginView();
                    }

                    public void onFacebookError(FacebookError e) {
                        // TODO Auto-generated method stub
                        Log.v("error", "error");
                    }

                    public void onError(DialogError e) {
                        // TODO Auto-generated method stub
                        Log.v("error", "error");
                    }
                });

And onActivityResult method: 和onActivityResult方法:

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

Since the onActivityResult not called, all the onComplete or onCancel method don't called either. 由于未调用onActivityResult,因此所有onComplete或onCancel方法均未调用。 The Intent.FLAG_ACTIVITY_NO_HISTORY is not defined so that's not the problem(this is mention on facebook page). 未定义Intent.FLAG_ACTIVITY_NO_HISTORY,所以这不是问题(在Facebook页面上已提及)。 If I set the activityCode to Facebook.FORCE_DIALOG_AUTH then when I clicked the button, the app not responding. 如果我将activityCode设置为Facebook.FORCE_DIALOG_AUTH,则当我单击按钮时,该应用程序无响应。 And I have facebook app installed on the device. 我在设备上安装了Facebook应用。 What should I do to call the onActivityResult method after authorize? 授权后该怎么办才能调用onActivityResult方法? Please someone help me with this since I can't find any solution anywhere. 请有人帮助我,因为我在任何地方都找不到任何解决方案。

Hope following Code will help you. 希望遵循《规范》对您有所帮助。

private static final String[] PERMISSIONS = new String[]
    { "publish_stream", "read_stream", "offline_access" };

mFacebook = new Facebook(APP_ID); 
mFacebook.authorize(this, PERMISSIONS,new LoginDialogListener());


private final class LoginDialogListener implements
            com.facebook.android.Facebook.DialogListener
    {

        /**
         * Called when the dialog has completed successfully
         */
        public void onComplete(Bundle values)
        {
            // Process onComplete
            Log.d("FB Sample App", "LoginDialogListener.onComplete()");
            // Dispatch on its own thread
            mHandler.post(new Runnable()
            {
                public void run()
                {
                    mText.setText("Facebook login successful. Press Menu...");
                }
            });
        }

        public void onFacebookError(FacebookError error)
        {
            // Process error
            Log.d("FB Sample App", "LoginDialogListener.onFacebookError()");
        }

        public void onError(DialogError error)
        {
            // Process error message
            Log.d("FB Sample App", "LoginDialogListener.onError()");
        }

        public void onCancel()
        {
            // Process cancel message
            Log.d("FB Sample App", "LoginDialogListener.onCancel()");
        }
    }

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

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