简体   繁体   中英

Android Facebook SDK 4.0 - Display username

I've been having a little trouble migrating to FB SDK's new version.

According to the documentation, this is how you fetch default user data:

GraphRequest request = GraphRequest.newMeRequest(
    accessToken,
    new GraphRequest.GraphJSONObjectCallback() {
        @Override
        public void onCompleted(
               JSONObject object,
               GraphResponse response) {
            // Application code
        }
    });
Bundle parameters = new Bundle();
parameters.putString("fields", "id,name,link");
request.setParameters(parameters);
request.executeAsync();

And I believe that the data is contained withing the JSONObject. However, I do not know how I can access and then use that user data.

Any help would be extremelly appreciated!

Thanks!

Now facebook sdk 4.0 doesnt return GraphUser it returns pure JSON object While working around with my android app i found someof the tags. Check this

{"id":"10000700XXXXXXX","birthday":"XX\/XX\/XXXX","email":"xxxxxx@gmail.com","first_name":"xxx","gender":"male","last_name":"xxxxx","link":"http:\/\/www.facebook.com\/10000700XXXXXXX","location":{"id":"1064427060XXXXX","name":"XXXX, XXXXXXXXXXX"},"locale":"en_US","name":"XXX XXXXX","timezone":5.5,"updated_time":"2015-03-27T13:33:02+0000","verified":true}

*************************************
public void onCompleted(JSONObject user, GraphResponse response) {
String id = user.optString("id");
String firstName = user.optString("first_name");
String lastName = user.optString("last_name");
and so on...

Request is executing in another thread, so you cannot write this data in array or variable, that initialized not in this thread. Instead you can set this data in any view you need. All time, when you want to write data between different threads, after operation you will have null object. Good luck)

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