Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
271 views
in Technique[技术] by (71.8m points)

android - How Do I Fetch Name and Email using Facebook SDK

I am using a TextView to show Name and Email of logged in facebook user, but i really don't know How do I fetch Name and Email ?

private void onSessionStateChange(Session session, SessionState state,
                                  Exception exception) {
    if (session != currentSession) {
        return;
    }

    if (state.isOpened()) {
        // Log in just happened.
        Toast.makeText(getApplicationContext(), "session opened",
                Toast.LENGTH_SHORT).show();
    } else if (state.isClosed()) {
        // Log out just happened. Update the UI.
        Toast.makeText(getApplicationContext(), "session closed",
                Toast.LENGTH_SHORT).show();
    }
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can get the name and email as below:

// use their Facebook info
    JSONObject json = Util.parseJson(facebook.request("me"));
    String facebookID = json.getString("id");
    String firstName = json.getString("first_name");
    String lastName = json.getString("last_name");
    Toast.makeText(uiActivity,"Thank you for Logging In, " 
                 + firstName + " " 
                 + lastName + "!"
                 , Toast.LENGTH_SHORT).show();

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...