Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/222.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/facebook/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Facebook android SDK4.0获取邮件地址_Android_Facebook_Facebook Graph Api - Fatal编程技术网

Facebook android SDK4.0获取邮件地址

Facebook android SDK4.0获取邮件地址,android,facebook,facebook-graph-api,Android,Facebook,Facebook Graph Api,Facebook已将API更改为4.0 如何获取用户的邮件地址 因为新类名为profile,所以无法获取它。 它可能从graph API回调 private void GraphAPIprofile() { GraphRequest request = GraphRequest.newMeRequest( AccessToken.getCurrentAccessToken(), new GraphRequest

Facebook已将API更改为4.0 如何获取用户的邮件地址 因为新类名为profile,所以无法获取它。 它可能从graph API回调

   private void GraphAPIprofile() {
        GraphRequest request = GraphRequest.newMeRequest(
                AccessToken.getCurrentAccessToken(),
                new GraphRequest.GraphJSONObjectCallback() {
                    @Override
                    public void onCompleted(
                            JSONObject object,
                            GraphResponse response) {
                        // Application code
                        Log.i("Graph API", response.toString());
                        Log.i("User Mail", object.optString("email"));

                    }
                });
        Bundle parameters = new Bundle();
        parameters.putString("fields", "id,name,email,gender, birthday");
        request.setParameters(parameters);
        request.executeAsync();
    }
我想我有点不对劲。。 请帮助,谢谢

尝试以下代码:-

if (Session.getActiveSession() == null
        || Session.getActiveSession().isClosed()) {
    Session.openActiveSession(this, true, new StatusCallback() {

        @Override
        public void call(Session session, SessionState state,
                Exception exception) {
            System.out.println("State= " + state);

            if (session.isOpened()) {
                System.out.println("Token=" + session.getAccessToken());
                Request.executeMeRequestAsync(session,
                        new GraphUserCallback() {
                            @Override
                            public void onCompleted(GraphUser user,
                                    Response response) {
                                if (user != null) {
                                    System.out.println("User=" + user);

                                }
                                if (response != null) {
                                    System.out.println("Response="
                                            + response);
                                    Toast.makeText(FBConnect.this,
                                            response.toString(),
                                            Toast.LENGTH_LONG).show();
                                }
                            }
                        });
            }
            if (exception != null) {
                System.out.println("Some thing bad happened!");
                exception.printStackTrace();
            }
        }
    });
}

将此代码写在您的活动的简历中或任何您想访问用户数据的地方。

是的,谢谢您的回复,我昨天就这么做了,但我认为这是旧API版本的代码。他们取消了会议。不,对我来说很好。用户对象包含您需要的所有信息