Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/207.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
Android Facebook SDK getBirthday()返回null_Android_Facebook - Fatal编程技术网

Android Facebook SDK getBirthday()返回null

Android Facebook SDK getBirthday()返回null,android,facebook,Android,Facebook,我试图在android应用程序中访问生日。但是生日返回空值。我可以访问除生日以外的所有其他数据 权限: loginButton = (LoginButton) findViewById(R.id.login_button); loginButton.setReadPermissions(Arrays.asList("basic_info", "user_birthday", "email", "user_friends")); 生日活动: Tools.LOG_INFO("bir

我试图在android应用程序中访问生日。但是生日返回空值。我可以访问除生日以外的所有其他数据

权限:

loginButton = (LoginButton) findViewById(R.id.login_button);
        loginButton.setReadPermissions(Arrays.asList("basic_info", "user_birthday", "email", "user_friends"));
生日活动:

Tools.LOG_INFO("birthday: " + user.getBirthday());
请试试这个:

 public void onClick(View v) {
    Logger.d(TAG, "Start FB session");
    // check if a session exists.
    Session currentSession = Session.getActiveSession();
    if (currentSession == null || currentSession.getState().isClosed()) {
        // create a new session.
        Session session = new Session.Builder(getApplicationContext()).build();
        // set it a the active session.
        Session.setActiveSession(session);
        // keep a variable link to session.
        currentSession = session;
    }
    // if a session is already open then issue a request using the available
    // session. Otherwise ask for user credentials.
    if (currentSession.isOpened()) {
        // The user is logged in.
        Logger.e(TAG, "User is logged in.");
        Session.getActiveSession().closeAndClearTokenInformation();
        Logger.i(TAG, "Session closed an token information cleared.");

        // get user data here with no extra call.
        Session.openActiveSession(this, true, new Session.StatusCallback() {
            @Override
            public void call(final 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) {
                                Logger.i(TAG, "User:" + user.getInnerJSONObject());
                            }
                        }
                    });
                }
            }
        });
    } else {
        // Ask for username and password
        OpenRequest op = new Session.OpenRequest((Activity) this);
        // don't use SSO.
        op.setLoginBehavior(SessionLoginBehavior.SUPPRESS_SSO);
        // no callback needed.
        op.setCallback(null);
        // set permissions.
        List<String> permissions = new ArrayList<String>();
        permissions.add("email");
        permissions.add("user_birthday");
        op.setPermissions(permissions);
        // open session for read.
        currentSession.openForRead(op);
        Logger.d(TAG, "Session open for read request issued.");
    }
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    Logger.d(TAG, "Request code is: " + requestCode);
    Logger.d(TAG, "Result code is: " + resultCode);
    super.onActivityResult(requestCode, resultCode, data);
    if (Session.getActiveSession() != null)
        Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);

    Session currentSession = Session.getActiveSession();
    if (currentSession == null || currentSession.getState().isClosed()) {
        Session session = new Session.Builder(getApplicationContext()).build();
        Session.setActiveSession(session);
        currentSession = session;
    }

    if (currentSession.isOpened()) {
        Session.openActiveSession(this, true, new Session.StatusCallback() {
            @Override
            public void call(final 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) {
                                Logger.i(TAG, "User:" + user.getInnerJSONObject());
                            }
                        }
                    });
                }
            }
        });
    }
}
public void onClick(视图v){
Logger.d(标记“启动FB会话”);
//检查会话是否存在。
会话currentSession=Session.getActiveSession();
如果(currentSession==null | | currentSession.getState().isClosed()){
//创建一个新会话。
会话会话=新建会话.Builder(getApplicationContext()).build();
//将其设置为活动会话的默认值。
Session.setActiveSession(Session);
//保持到会话的可变链接。
当前会话=会话;
}
//如果会话已打开,则使用可用的
//会话。否则,请求用户凭据。
if(currentSession.isOpened()){
//用户已登录。
Logger.e(标记“用户已登录”);
Session.getActiveSession().closeAndClearTokenInformation();
i(标记“会话关闭,令牌信息清除”);
//在这里获取用户数据,无需额外调用。
Session.openActiveSession(此为true,新Session.StatusCallback(){
@凌驾
公共无效调用(最终会话、会话状态、异常){
if(session.isOpened()){
Request.executeRequestAsync(会话,新请求.GraphUserCallback(){
@凌驾
未完成公共无效(GraphUser用户,响应){
如果(用户!=null){
Logger.i(标记“User:+User.getInnerJSONObject());
}
}
});
}
}
});
}否则{
//询问用户名和密码
OpenRequest op=newsession.OpenRequest((活动)this);
//不要使用SSO。
op.setLoginBehavior(SessionLoginBehavior.SUPPRESS_SSO);
//不需要回调。
op.setCallback(空);
//设置权限。
列表权限=新建ArrayList();
权限。添加(“电子邮件”);
权限。添加(“用户生日”);
op.setPermissions(权限);
//打开会话进行读取。
当前会话.openForRead(op);
Logger.d(标记“会话打开以发出读取请求”);
}
}
@凌驾
ActivityResult上的公共void(int请求代码、int结果代码、意图数据){
Logger.d(标签,“请求代码为:”+requestCode);
Logger.d(标记,“结果代码为:”+resultCode);
super.onActivityResult(请求代码、结果代码、数据);
if(Session.getActiveSession()!=null)
Session.getActiveSession().onActivityResult(此、请求代码、结果代码、数据);
会话currentSession=Session.getActiveSession();
如果(currentSession==null | | currentSession.getState().isClosed()){
会话会话=新建会话.Builder(getApplicationContext()).build();
Session.setActiveSession(Session);
当前会话=会话;
}
if(currentSession.isOpened()){
Session.openActiveSession(此为true,新Session.StatusCallback(){
@凌驾
公共无效调用(最终会话、会话状态、异常){
if(session.isOpened()){
Request.executeRequestAsync(会话,新请求.GraphUserCallback(){
@凌驾
未完成公共无效(GraphUser用户,响应){
如果(用户!=null){
Logger.i(标记“User:+User.getInnerJSONObject());
}
}
});
}
}
});
}
}

虽然可以使用,但函数executeMeRequestAsync已被弃用:)