1

在此代码中,GraphUser 未返回电子邮件 ID 和联系电话。

 @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        uiHelper.onSaveInstanceState(outState);
    }

    private void onSessionStateChange(Session session, SessionState state, Exception exception) {
        if (state.isOpened()) {
            // userInfoTextView.setVisibility(View.VISIBLE);

                // Request user data and show the results
                Request.executeMeRequestAsync(session, new Request.GraphUserCallback() {

                    @Override
                    public void onCompleted(GraphUser user, Response response) {
                        if (user != null) {
                            // Display the parsed user info

                        String email=   (String) response.getGraphObject().getProperty("email");

                            System.out.println("yahooooooooooo  "+email);
                            buildUserInfoDisplay(user);
                        }
                    }
                });
        } else if (state.isClosed()) {
            Log.i(TAG, "Logged out...");
        }
    }

    private String buildUserInfoDisplay(GraphUser user) {
        StringBuilder userInfo = new StringBuilder("");



        // Example: typed access (name)
        // - no special permissions required
        userInfo.append(String.format("Name: %s\n\n", 
            user.getName()));

        // Example: typed access (birthday)
        // - requires user_birthday permission
        userInfo.append(String.format("Birthday: %s\n\n", 
            user.getBirthday()));


        userInfo.append(String.format("Birthday: %s\n\n", 
                user.getBirthday()));


        userInfo.append(String.format("Gender: %s\n\n", 
                user.getProperty("gender")));

        userInfo.append(String.format("Iddddddd: %s\n\n", 
                user.getId()));
        // Example: partially typed access, to location field,
        // name key (location)
        // - requires user_location permission
        userInfo.append(String.format("Location: %s\n\n", 
            user.getLocation().getProperty("name")));

        // Example: access via property name (locale)
        // - no special permissions required
        userInfo.append(String.format("Locale: %s\n\n", 
            user.getProperty("locale")));
        return userInfo.toString();
    }
4

2 回答 2

9

默认情况下您不会收到电子邮件,对于电子邮件,您必须指定权限

Session.StatusCallback statusCallback = new Session.StatusCallback() 
        {

            @Override
            public void call(Session session, SessionState state, Exception exception) 
            {
                if(session.isOpened())
                {
                    Request.executeMeRequestAsync(session, new Request.GraphUserCallback() 
                    {

                        @Override
                        public void onCompleted(GraphUser user, Response response) 
                        {

                            if(user != null)
                            {
                                try
                                {
                                    System.out.println("Graph Inner Json"+user.getInnerJSONObject());
                                    String email = user.getInnerJSONObject().getString("email");
                                }
                             }
                         }
                     }
                 }
            }

YourActivityName.openActiveSession(this, true, statusCallback);

这是openActiveSession()我们指定权限的地方

private static Session openActiveSession(Activity activity, boolean allowLoginUI, Session.StatusCallback statusCallback)
    {
        OpenRequest openRequest = new OpenRequest(activity);
        openRequest.setPermissions(Arrays.asList("user_birthday", "email"));
        openRequest.setCallback(statusCallback);

        Session session = new Session.Builder(activity).build();

        if(SessionState.CREATED_TOKEN_LOADED.equals(session.getState()) || allowLoginUI)
        {
            Session.setActiveSession(session);
            session.openForRead(openRequest);

            return session;
        }

        return null;
    }

并且在里面onActivityResult()不要忘记做

if(Session.getActiveSession() != null)
        {
            Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
        }
于 2013-06-13T08:02:43.843 回答
1

我遇到了另一种情况,我通过了所有权限,但仍然收到错误“电子邮件没有价值”。这背后的原因是没有为该 Facebook 帐户验证主要电子邮件(要查看 Facebook 中的主要电子邮件,请转到帐户设置--> 电子邮件)。因此,如果没有为 Facebook 帐户验证主要电子邮件,那么您将始终收到此错误。请确保您正在访问的 Facebook 帐户有一个经过验证的主电子邮件。

于 2013-10-26T06:35:32.463 回答