无法让FB用户生日

无法让FB用户生日

本文介绍了无法让FB用户生日,android?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取Facebook用户的个人资料信息,如姓名,电子邮件,生日和位置。我不能得到用户的生日。

  callbackManager = CallbackManager.Factory.create(); 
loginManager = LoginManager.getInstance();
loginManager.registerCallback(callbackManager,new FacebookCallback< LoginResult>(){
@Override
public void onSuccess(LoginResult loginResult){
// App code
accessToken = AccessToken.getCurrentAccessToken();
getProfileInformationFacebook(accessToken);
Log.e(login res,loginResult.toString());
}

@Override
public void onCancel(){
//应用程序代码
}

@Override
public void onError(FacebookException exception){
/ /应用代码
}
});

阅读权限:

  loginManager.logInWithReadPermissions(this,
Arrays.asList(user_about_me,user_birthday,user_location,email));

图API请求:

  public void getProfileInformationFacebook(AccessToken accToken){
GraphRequest request = GraphRequest.newMeRequest(
accToken,
new GraphRequest.GraphJSONObjectCallback(){
@Override
public void onCompleted(
JSONObject对象,
GraphResponse响应){
Log.e(object,object.toString());
String fbId = null;
String fbBirthday = null;
String fbLocation = null;
String fbEmail = null;
String fbName = null;

try {
fbId = object.getString(id);
fbEmail = object.getString(email);
fbName = object.getString(name );
fbBirthday = object.getString(birthday);
JSONObject jsonObject = object.getJSONObject(location);
fbLocation = jsonObject.getString(name);
} catch(JSONException e){
e.printStackTrace();
}
}
});
Bundle parameters = new Bundle();
parameters.putString(fields,id,name,email,location,birthday);
request.setParameters(parameters);
request.executeAsync();

图API响应:

  {id:10153618779823958,email:[email protected],name:Wishy Gupta} 
pre>

这里有一些东西吗?

解决方案

Facebook不要给予用户生日。您必须使用扩展权限将您的应用程序提交给Facebook 以访问用户的生日。



参见这里:




I am trying to get some profile information of facebook user like name, email, birthday and location. I am not able to get the user's birthday.

callbackManager = CallbackManager.Factory.create();
    loginManager=LoginManager.getInstance();
    loginManager.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
        @Override
        public void onSuccess(LoginResult loginResult) {
            // App code
            accessToken = AccessToken.getCurrentAccessToken();
            getProfileInformationFacebook(accessToken);
            Log.e("login res", loginResult.toString());
        }

        @Override
        public void onCancel() {
            // App code
        }

        @Override
        public void onError(FacebookException exception) {
            // App code
        }
    });

Read permissions:

loginManager.logInWithReadPermissions(this,
                Arrays.asList("user_about_me", "user_birthday", "user_location", "email"));

Graph API request:

public void getProfileInformationFacebook(AccessToken accToken) {
    GraphRequest request = GraphRequest.newMeRequest(
            accToken,
            new GraphRequest.GraphJSONObjectCallback() {
                @Override
                public void onCompleted(
                        JSONObject object,
                        GraphResponse response) {
                    Log.e("object", object.toString());
                    String fbId = null;
                    String fbBirthday = null;
                    String fbLocation = null;
                    String fbEmail = null;
                    String fbName = null;

                    try {
                        fbId = object.getString("id");
                        fbEmail = object.getString("email");
                        fbName = object.getString("name");
                        fbBirthday = object.getString("birthday");
                        JSONObject jsonObject = object.getJSONObject("location");
                        fbLocation = jsonObject.getString("name");
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            });
    Bundle parameters = new Bundle();
    parameters.putString("fields", "id,name,email,location,birthday");
    request.setParameters(parameters);
    request.executeAsync();

Graph API response:

{"id":"10153618779823958","email":"[email protected]","name":"Wishy Gupta"}

Is here something missing?

解决方案

Facebook don't give user birthday by default.You have to use extended permission and submit your app for review to facebook to access user`s birthday.

See here:

https://developers.facebook.com/docs/facebook-login/permissions/v2.4

这篇关于无法让FB用户生日,android?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 00:25