4

如何获得用户生日user.getBirthday()

Session.openActiveSession(this, true, new Session.StatusCallback() {
      // callback when session changes state
      @Override
      public void call(Session session, SessionState state, Exception exception) {
        if (session.isOpened()) {

          // make request to the /me API
          Request.executeMeRequestAsync(session, new Request.GraphUserCallback() {

            // callback after Graph API response with user object
            @Override
            public void onCompleted(GraphUser user, Response response) {
              if (user != null) {
                TextView welcome = (TextView) findViewById(R.id.textView1);
                welcome.setText("Hello " + user.getBirthday() + "!");
                Log.d("user_birthday","user_birthday:"+user.getBirthday());//user.getBirthday()  this value always is null?
              }
            }
          });
        }
      }
    });
4

2 回答 2

7

首先,您是否为 user_birthday 设置了权限?如果您想访问 user_birthday 信息,这一点非常重要

如果用户不为空,通常您可以通过 user.getBirthday() 获取生日,因为据我所知,您正在使用新的 facebook SDK

例如,当您使用 facebook authbutton 时,您可以设置权限

authButton.setReadPermissions(Arrays.asList("user_location", "user_birthday", "user_likes"));

或者您可以重新授权权限

Session.ReauthorizeRequest reauthRequest = new Session.ReauthorizeRequest(this, PERMISSIONS).
                    setRequestCode(REAUTHORIZE_ACTIVITY).
                    setLoginBehavior(SessionLoginBehavior.SSO_WITH_FALLBACK);
session.reauthorizeForPublish(reauthRequest);

其中 PERMISSION 是包含您的权限的数组

于 2013-03-19T09:24:23.247 回答
0

小提示:可以通过初始打开会话请求来请求权限,因此无需重新授权:

final Session.OpenRequest request = new Session.OpenRequest(Activity.this);
request.setPermissions(Arrays.asList("email", "user_birthday")); // Your permissions here
request.setCallback(new Session.StatusCallback()
{
    @Override
    public void call(final Session session, SessionState state, Exception exception)
    {
        if (session.isOpened())
        {
            // Your code here
        }
    }
});

Session fbSession = Session.getActiveSession();
if (fbSession == null || fbSession.isClosed())
{
    fbSession = new Session(Activity.this);
    Session.setActiveSession(fbSession);
}

fbSession.openForRead(request);

Activity.this - 你的活动上下文。

希望这对某人有帮助.. :)

于 2014-05-24T11:00:32.813 回答