Skip to content Skip to sidebar Skip to footer

How To Get Id And Name From Facebook Profile Using Facebook Sdk?

I know that the way is using JSON and i have read much about how to do it, but i still can't figure out WHERE i have to put the JSON code so i can get the id and name, because ever

Solution 1:

u can use this: (this code is using Facebook SDK 3.02)

user id:

finalSessionsession= Session.getActiveSession();
    if (session != null && session.isOpened()) {
        // If the session is open, make an API call to get user data// and define a new callback to handle the responseRequestrequest= Request.newMeRequest(session, newRequest.GraphUserCallback() {
            @OverridepublicvoidonCompleted(GraphUser user, Response response) {
                // If the response is successfulif (session == Session.getActiveSession()) {
                    if (user != null) {
                        user_ID = user.getId();//user id
                        profileName = user.getName();//user's profile name
                        userNameView.setText(user.getName());
                    }   
                }   
            }   
        }); 
        Request.executeBatchAsync(request);
    }  

user_ID & profileName are string.

Solution 2:

Try this:

AsyncFacebookRunnermyAsyncRunner=newAsyncFacebookRunner(facebook);
JSONObjectjson= Util.parseJson(myAsyncRunner.request("me", newmeRequestListener()));
                    StringfacebookID= json.getString("id");
                    StringfirstName= json.getString("name");                  
                    System.out.println("Details: "+id+" "+name);

I hope this will be help to you..

Solution 3:

This was the solution

Stringresponse= facebook.request("me", param, "GET");

Hope it helps someone who had similar problem.

Post a Comment for "How To Get Id And Name From Facebook Profile Using Facebook Sdk?"