如何通过uid统计Facebook用户的好友总数?

发布于 2024-09-15 09:03:41 字数 49 浏览 5 评论 0原文

如何通过 uid 统计 Facebook 用户的好友总数?

How can I count the total friends of a Facebook user by uid?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

相权↑美人 2024-09-22 09:03:49

有很多方法可以计算使用 Facebook Graph API 和 Php SDK 的朋友数量,其中之一是我告诉的。

$fbuser=$fb->api('/me/friends');
$access_token = $fb->getAccessToken();


$friend_count=0;
foreach($fbuser['data'] as $friends)
{
  $friends_count++;
}

有关完整的教程,请访问这篇文章 获取 FB 好友计数

There are lot of way to count the no of friends using Facebook Graph API with Php SDK, out of one i am telling..

$fbuser=$fb->api('/me/friends');
$access_token = $fb->getAccessToken();


$friend_count=0;
foreach($fbuser['data'] as $friends)
{
  $friends_count++;
}

For complete tutorial visit this article Getting FB Friends Count

暮凉 2024-09-22 09:03:48

Facebook API 2.0 开始,您无法获取 Facebook 好友的完整列表,仅获取也授权您的应用的好友的部分列表。

不过,您仍然可以获得好友总数,Graph API user /friends 有一个字段 summary,其中包含 total_count 计数,

因此您可以使用以下方式获取它:

FB.api("/me/friends", function (response) {
   if (response && !response.error) {
      console.log(response.summary.total_count);
   }
});

Starting with Facebook API 2.0 you can't get the full list of Facebook friends, only a partial list of friends that also authorized your app.

You can still get the total number of friends though, the Graph API user/friends has a field summary containing the count as total_count

So you can get it using:

FB.api("/me/friends", function (response) {
   if (response && !response.error) {
      console.log(response.summary.total_count);
   }
});
永言不败 2024-09-22 09:03:47

这是我的解决方案...效果很好!

$myfriends = $facebook->api('/XXXXXXX152466/friends');
$friendcount =  COUNT($myfriends['data']) + 1;

将 XXXXXXX152466 替换为 facebook 个人资料 id#

使用 Facebook PHP SDK 以及 Graph API!

Heres my solution... works great!

$myfriends = $facebook->api('/XXXXXXX152466/friends');
$friendcount =  COUNT($myfriends['data']) + 1;

Replace XXXXXXX152466 with the facebook profile id#

Using Facebook PHP SDK along with Graph API!

以可爱出名 2024-09-22 09:03:46

FQL 不支持 COUNT

SELECT uid2 
FROM friend 
WHERE uid1 = USERID

由于不支持 COUNT,因此您需要获取所有记录,然后在进行 SQL 调用的任何应用程序中对它们进行计数。

如果您想获取更多信息,例如姓名和计数,您可以使用内部选择来获取朋友的扩展信息:

SELECT name 
FROM user 
WHERE uid IN (SELECT uid2 
              FROM friend 
              WHERE uid1 = USERID)

这是一个相关的SO问题:

FQL 结果计数

朋友的参考

查询该表以确定是否
两个用户链接在一起
朋友们。

COUNT is not supported by FQL:

SELECT uid2 
FROM friend 
WHERE uid1 = USERID

Since COUNT is not supported you need to get all of the records and then count them in whatever application that is making the SQL call.

If you want to get more information, like names, along with count you can use an inner select to get the friend's extended info:

SELECT name 
FROM user 
WHERE uid IN (SELECT uid2 
              FROM friend 
              WHERE uid1 = USERID)

Here is a related SO question:

FQL result count

References for Friend table:

Query this table to determine whether
two users are linked together as
friends.

调妓 2024-09-22 09:03:45

自 2014 年 10 月起,FQL 现已弃用。引用 Facebook 的常见问题解答:

自 2014 年 7 月 22 日星期二起,我们现在返回一个 Total_count 字段
对 /v2.2/me/friends 的响应中的摘要属性。

用户/朋友端点确实需要 user_friends 权限才能返回使用您的应用程序的朋友的实际列表,但是如果没有授予 user_friends 权限,仍然会返回朋友计数字段。回复示例:

    {
  "data": [
  ], 
  "summary": {
    "total_count": 811
  }
}

完整常见问题解答:https://developers.facebook.com/docs/apps/faq#total_friend_count

FQL is now deprecated as of October 2014. Quoting Facebook's FAQ :

As of Tuesday 22nd July 2014, we now return a total_count field within
a summary property in the response to /v2.2/me/friends.

The user/friends endpoint does require the user_friends permission to return an actual list of friends who use your app, however the friend count field will still be returned without this the user_friends permission granted. Sample response:

    {
  "data": [
  ], 
  "summary": {
    "total_count": 811
  }
}

Full FAQ: https://developers.facebook.com/docs/apps/faq#total_friend_count

Oo萌小芽oO 2024-09-22 09:03:44

@Scott

这非常有效,我没想到它会:)

https://graph.facebook.com/fql?q=SELECTfriend_count FROM user WHERE uid = 273103345

我尝试使用一个随机用户 ID,该用户 ID 不是 Graph API 中的好友。然而,对于少数随机 uid,它返回 null,我猜它们是页面。

@Scott

This very much works, I didn't expect it to :)

https://graph.facebook.com/fql?q=SELECT friend_count FROM user WHERE uid = 273103345

I tried with a random user id who is not a friend in Graph API. However for few random uids it returned null, I am guessing they were pages.

老子叫无熙 2024-09-22 09:03:43

您可以查询 user 表中有一个 friend_count 字段。

SELECT friend_count FROM user WHERE uid = me()

只需将 me() 替换为您要查询的用户的 UID 即可。

There is a friend_count field against the user table that you can query.

SELECT friend_count FROM user WHERE uid = me()

Just replace me() with the UID of the user that you want to query.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文