Android FB logInWithReadPermissions和registerCallback WITHOUT登录按钮

时间:2015-06-25 22:00:57

标签: android facebook facebook-login

对此感到生气。我尝试登录FB并同时检索用户信息。

FB登录正常,应用程序更改为FB,显示应用程序要求的权限,按“接受”后,返回到我的应用程序。但是从不调用registerCallback。我的错误在哪里?在这里我的代码:

        FacebookSdk.sdkInitialize(getApplicationContext());
        CallbackManager mCallbackManager = CallbackManager.Factory.create();
        LoginManager.getInstance().logInWithReadPermissions(
                this,
                permissionNeeds);

        LoginManager.getInstance().registerCallback(mCallbackManager,
                new FacebookCallback<LoginResult>() {
                    @Override
                    public void onSuccess(LoginResult loginResult) {
                        Log.e("dd", "SUCCESS");

                        GraphRequest.newMeRequest( loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() {

                                    @Override
                                   public void onCompleted(JSONObject json, GraphResponse response) {
                                        if (response.getError() != null) {
                                            System.out.println("ERROR");
                                        } else {
                                            System.out.println("Success");
                                            try {
                                                String jsonresult = String.valueOf(json);
                                                System.out.println("JSON Result" + jsonresult);
                                                String str_email = json.getString("email");
                                                String str_id = json.getString("id");
                                                String str_firstname = json.getString("first_name");
                                                String str_lastname = json.getString("last_name");
                                            } catch (JSONException e) {
                                                e.printStackTrace();
                                            }
                                        }
                                    }
                                }).executeAsync();
                    }

                    @Override
                    public void onCancel() {

                        Log.e("dd", "facebook login canceled");

                    }


                    @Override
                    public void onError(FacebookException e) {


                        Log.e("dd", "facebook login failed error");

                    }
                });

1 个答案:

答案 0 :(得分:5)

编辑:

发现它,以下代码丢失,现在我在登录后获取用户信息

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