简体   繁体   English

Android Facebook SDK 4.0-显示用户名

[英]Android Facebook SDK 4.0 - Display username

I've been having a little trouble migrating to FB SDK's new version. 迁移到FB SDK的新版本时遇到了一些麻烦。

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. 而且我相信数据包含在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. 现在,Facebook SDK 4.0不返回GraphUser,而是返回纯JSON对象。在使用我的Android应用程序时,我发现了一些标签。 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) 祝好运)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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