在Android的Facebook API - 我怎样才能得到一个用户拥有朋友的数量? [英] facebook api on android - how can I get the number of friends that a user has?

查看:234
本文介绍了在Android的Facebook API - 我怎样才能得到一个用户拥有朋友的数量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建与Facebook登录的应用程序,而我现在能够通过Facebook的API成功登录用户的Facebook!

不过,我也试图收集有关用户,现有的朋友,他们就是有多少的一些信息。

请注意,我不是在寻找朋友的完整列表(我不知道是否有一个奇怪的事情的权限有或没有),而是我只想找一个朋友说用户有多少。

我有codeD以下,但如果它的工作原理还是因为我无法实际访问,我在请求调用外的请求调用创建变量我无法验证不行。我猜有可能是一个更简单(更准确)来完成获取好友的号码,使用户拥有...

这是如何做到这一点任何想法?

 新的请求(
                    Session.getActiveSession(),
                    /我的/朋友
                    空值,
                    HttpMethod.GET,
                    新Request.Callback(){
                        公共无效onCompleted(响应响应){
                           //处理结果
                            最终诠释iFacebookFollowerCount =(整数)response.getGraphObject()的getProperty(TOTAL_COUNT);
                        }
                    }
            );


解决方案

  authButton.setReadPermissions(Arrays.asList(user_friends);

authbutton是FB登录按钮。

您需要得到许可,是这样的。

您可以检查的权限是由您的访问令牌下面的ID检查理所当然的。如果授予权限,你可以得到的总数

https://graph.facebook.com/me?fields=friends {朋友}&放大器;的access_token =

响应样本

I am creating an app with facebook login, and I am now able to successfully log in the user to facebook via the facebook api!

However, I am also trying to gather some information on the user, namely the number of existing friends that they have.

Note that I am NOT looking for the full list of friends (I don't know if there is an odd permission thing there or not) BUT instead I am looking only for the number of friends that the user has.

I have coded the below, but I cannot verify if it works or not because I cannot actually access the variable that I create in the request call outside of the request call. I'm guessing that there is probably a simpler (and more accurate) way to accomplish obtaining the number of friends that the user has...

Any ideas on how to accomplish this?

            new Request(
                    Session.getActiveSession(),
                    "/me/friends",
                    null,
                    HttpMethod.GET,
                    new Request.Callback() {
                        public void onCompleted(Response response) {
                           // handle the result
                            final int iFacebookFollowerCount = (Integer) response.getGraphObject().getProperty("total_count");
                        }
                    }
            );

解决方案

authButton.setReadPermissions(Arrays.asList("user_friends");

authbutton is fb login button..

You need to get permission like this.

you can check if the permission is granted by checking on the following id with your access token. If the permission is granted you can get the total count

https://graph.facebook.com/me?fields=friends{friends}&access_token=

response sample

这篇关于在Android的Facebook API - 我怎样才能得到一个用户拥有朋友的数量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆