简体   繁体   中英

Get username in Facebook SDK 4 android

I need to get the username of a Profile after logging in. this is my code:

    @Override
    public void onSuccess(LoginResult loginResult) {
       
        GraphRequest.newMeRequest(loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() {
                    @Override
                    public void onCompleted(JSONObject me, GraphResponse response) {
                        if (response.getError() != null) {
                            // handle error
                        } else {
                            String email = me.optString("email");
                            String id = me.optString("id");
                            String nick = me.optString("username ");
                            if(nick==""){
                                nick = me.optString("name");
                            }
                            // send email and id to your web server
                            ArrayList<String> keys = new ArrayList<String>(Arrays.asList("idGoogle","email","idEntity","nickname"));
                            ArrayList<String> values = new ArrayList<String>(Arrays.asList(id, email, entity.getIDENTITY().toString(),nick));
                            
                            new loginUser(keys,values,"newFacebookUser",id,FACEBOOK).execute();
                        }
                    }
                }).executeAsync();
   }    
   

What do I have to do to get the username of the profile?

/me/username is no longer available.

Source

Since v2.0 of the Graph API, it´s not possible to get the username anymore. Use the (App Scoped) ID to identify users.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM