Request.newMeRequest永远不会返回

时间:2014-01-23 16:57:42

标签: java android facebook

我正在使用Request.newMeRequest()通过facebook登录获取用户的电子邮件和姓名,我正在使用以下代码块。

此代码存在于名为SignUp的活动中,用户也可以从MainActivity导航。

我的问题是,在输入电子邮件和密码并成功授予Facebook权限后,应用程序将返回MainActivity状态,而其余功能(onCompleted部分)永远不会被触发。

private void performFacebookLogin()
{
    Log.d("FACEBOOK", "performFacebookLogin");
    final Session.NewPermissionsRequest newPermissionsRequest = new Session.NewPermissionsRequest(this, Arrays.asList("email"));
    Session openActiveSession = Session.openActiveSession(this, true, new Session.StatusCallback()
    {
        @Override
        public void call(Session session, SessionState state, Exception exception)
        {
            Log.d("FACEBOOK", "call");
            if (session.isOpened() && !isFetching)
            {
                Log.d("FACEBOOK", "if (session.isOpened() && !isFetching)");
                isFetching = true;
                session.requestNewReadPermissions(newPermissionsRequest);
                Request getMe = Request.newMeRequest(session, new GraphUserCallback()
                {
                    @Override
                    public void onCompleted(GraphUser user, Response response)
                    {
                        Log.d("FACEBOOK", "onCompleted");
                        if (user != null)
                        {
                            Log.d("FACEBOOK", "user != null");
                            org.json.JSONObject graphResponse = response.getGraphObject().getInnerJSONObject();
                            String email = graphResponse.optString("email");
                            String id = graphResponse.optString("id");
                            String facebookName = user.getUsername();
                            if (email == null || email.length() < 0)
                            {
                                AlertDialog alertDialog = new AlertDialog.Builder(getApplicationContext()).create();
                                alertDialog.setTitle("Facebook Login");
                                alertDialog.setMessage("An email address is required for your account, we could not find an email associated with this Facebook account. Please associate a email with this account.");
                                alertDialog.setButton("Ok",new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog, int id) {
                                        dialog.cancel();
                                    }
                                });
                                alertDialog.show();

                                return;
                            }
                        }
                    }
                });
                getMe.executeAsync();
            }
            else
            {
                if (!session.isOpened())
                    Log.d("FACEBOOK", "!session.isOpened()");
                else
                    Log.d("FACEBOOK", "isFetching");

            }
        }
    });
}

Log.d("FACEBOOK", "onCompleted");永远不会被称为

我在我的SignUp活动中重写onActivityResult,如下所示,这也永远不会被调用

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    Log.d("FACEBOOK", "onActivityResult");
    Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
}

0 个答案:

没有答案