我正在尝试从Facebook获取当前登录用户的性别和生日,但是我一直都在搜索(id,电子邮件,姓名)与此相关的所有内容,但由于查找不完全正确。下面的代码,我有尝试不起作用。
facebookLoginButton = (LoginButton)view .findViewById(R.id.fragment_login_facebook);
facebookLoginButton.setFragment(this);
callbackManager = CallbackManager.Factory.create();
facebookLoginButton.setReadPermissions(Arrays.asList("public_profile", "email", "user_birthday", "user_friends"));
callbackManager = CallbackManager.Factory.create();
facebookLoginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
private ProfileTracker mProfileTracker;
@Override
public void onSuccess(LoginResult loginResult) {
String accessTocken = loginResult.getAccessToken().getToken().toString();
Log.v("TAG", "Access Token " + loginResult.getAccessToken().getToken());
GraphRequest request = GraphRequest.newMeRequest(
loginResult.getAccessToken(),
new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject object, GraphResponse response) {
try {
String email = object.getString("birthday");
String name = object.getString("gender");
Toast.makeText(getActivity().getApplicationContext(),email + " " + name ,Toast.LENGTH_SHORT).show();
} catch (JSONException e) {
e.printStackTrace();
}
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "id,name,email,gender,birthday");
request.setParameters(parameters);
request.executeAsync();
if (com.facebook.Profile.getCurrentProfile() == null){
mProfileTracker = new ProfileTracker() {
@Override
protected void onCurrentProfileChanged(com.facebook.Profile oldProfile, com.facebook.Profile currentProfile) {
mProfileTracker.stopTracking();
}
};
mProfileTracker.startTracking();
} else {
com.facebook.Profile profile = com.facebook.Profile.getCurrentProfile();
}
try {
URL image_value = new URL("http://graph.facebook.com/" + loginResult.getAccessToken().getUserId() + "/picture?type=large");
Log.v(Constants.TAG, image_value + "");
} catch (Exception e) {
}
}
@Override
public void onCancel() {
Log.e("TAG", "wrong");
}
@Override
public void onError(FacebookException error) {
Log.e("TAG", "wrong");
}
});
其中facebookLoginButton是LoginButton,而callbackManager是CallbackManager 请事先帮助我。
答案 0 :(得分:6)
gender
和birthday
需要进行应用审查。需要进行应用审查的应用
如果您的应用使用以下功能,则需要进行审核:
Facebook登录名,还询问一个人的生日,位置,家乡,性别,年龄范围或个人资料链接