How can i get user information from Latest Facebook sdk-4.0.1 ,, like :
email - user_birthday - user_friends
Notice : I use LoginButton
final LoginButton loginButton = (LoginButton) findViewById(R.id.login_button);
loginButton.setReadPermissions("user_friends");
loginButton.setReadPermissions("public_profile");
loginButton.setReadPermissions("email");
loginButton.setReadPermissions("user_birthday");
First, the permissions can be setup in one line:
loginButton.setReadPermissions(Arrays.asList("user_friends, public_profile, email, user_birthday"));
Now, considering you registered a callback in this way:
loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) { }
@Override
public void onCancel() { }
@Override
public void onError(FacebookException exception) { }
});
Place this code in the onSuccess() method:
GraphRequest request = GraphRequest.newMeRequest( loginResult.getAccessToken(),
new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted( JSONObject object, GraphResponse response) {
Log.d("onCompleted",object.toString());
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "id,name,link, email");
request.setParameters(parameters);
request.executeAsync();
Pay attention in this line:
parameters.putString("fields", "id,name,link, email");
...these will be the fields returned in the JSONObject in the onCompleted()
method.
Reference:
https://developers.facebook.com/docs/graph-api/using-graph-api/v2.3#reading https://developers.facebook.com/docs/graph-api/reference/user
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.