Reputation: 5196
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!
Upvotes: 1
Views: 1351
Reputation: 1757
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)
Upvotes: 1
Reputation: 1939
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":"[email protected]","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...
Upvotes: 4