• 我尝试使用LoginButton登录,但未调用登录回调。(LoginButton在Fragment中)。
  • FacebookSdk.sdkInitialize在应用程序onCreate上调用
  • 登录完成后,未调用任何回调。
    这是代码:

  • Activity :
    public class FrameActivity extends BaseActivity {
    
     public static CallbackManager callbackManager;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    // FacebookSdk.sdkInitialize is called in the Application onCreate
    
    callbackManager = CallbackManager.Factory.create();
    }
    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        callbackManager.onActivityResult(requestCode, resultCode, data);
    
    }
    }
    

    分段:
     @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_login, container, false);
        LoginButton loginButton = (LoginButton) view.findViewById(R.id.login_button);
        loginButton.setReadPermissions("user_friends");
        loginButton.setReadPermissions("public_profile");
        loginButton.setReadPermissions("email");
        loginButton.setReadPermissions("user_birthday");
        // If using in a fragment
        loginButton.setFragment(this);
        // Other app specific specialization
    
        // Callback registration
        loginButton.registerCallback(FrameActivity.callbackManager, new FacebookCallback<LoginResult>() {
            @Override
            public void onSuccess(LoginResult loginResult) {
    
    
    }
            @Override
            public void onCancel() {
                // App code
    
            }
    
            @Override
            public void onError(FacebookException exception) {
                // App code
    
            }
        });
        return view;
    }
    

    最佳答案

    尝试这个:

  • 在片段的FacebookSdk.sdkInitialize()中初始化onCreateView()
  • 下一行init callbackManager = CallbackManager.Factory.create();
  • 在Fragment类中的onActivityResult()上实现。
  • 添加您的callbackManager.onActivityResult(requestCode, resultCode, data);在片段onActivityResult()中。

  • 确保从 Activity 中删除FacebookInit()callbackManager

    关于android - Facebook登录CallbackManager FacebookCallback不被调用吗?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29557486/

    10-10 20:04