简体   繁体   English

Facebook:如何获得朋友数量?

[英]Facebook : how to get number of friends?

I would like to be able to retrieve some people number of friends on Facebook. 我希望能够在Facebook上检索到一些朋友。 However, I got some issue to achieve this goal. 但是,我在实现此目标时遇到了一些问题。 I tried two different ways: 我尝试了两种不同的方法:

1. With FQL: 1.使用FQL:

I tried following query : 我尝试了以下查询

SELECT username, friend_count
FROM user
WHERE username = jonathan.petitcolas

But, as you can see, the friend_count property is always null. 但是,您可以看到,friend_count属性始终为null。 On my public profile, and also on other profiles. 在我的公开个人资料以及其他个人资料上。

2. With Facebook PHP SDK 2.使用Facebook PHP SDK

Then, I installed the Facebook PHP SDK, created an application, and did the following: 然后,我安装了Facebook PHP SDK,创建了一个应用程序,并执行以下操作:

$facebook = new \Facebook(array(
    'appId' => 'XXX',
    'secret' => 'XXX'
));

$friends = $facebook->api('/jonathan.petitcolas/friends');

Then I got the following exception: 然后我得到以下异常:

[FacebookApiException] [FacebookApiException]
(#604) Can't lookup all friends of 676944843. Can only lookup for the logged in user or the logged in user's friends that are users of your app. (#604)无法查找676944843的所有朋友。只能查找已登录用户或作为您应用程序用户的登录用户的朋友。

Indeed, I am logged in with another user. 确实,我是用另一个用户登录的。

So, is it possible to retrieve number of friends of a public profile on Facebook? 那么,是否有可能在Facebook上检索公开个人资料的朋友数量? Is so, how to do this? 是这样,该怎么做?

Thanks a lot! 非常感谢! :) :)

I tried following query: 我尝试了以下查询:

SELECT username, friend_count
FROM user
WHERE username = jonathan.petitcolas

But, as you can see, the friend_count property is always null. 但是,您可以看到,friend_count属性始终为null。 On my public profile, and also on other profiles. 在我的公开个人资料以及其他个人资料上。

Nope, it's not always null. 不,并非总是null。 If I do that query with my own user name (and correcting the syntax error in your query), I get back the correct number of friends. 如果我使用自己的用户名进行查询(并更正查询中的语法错误),那么我将获得正确数量的朋友。 Only if I authenticated that app making the query, of course. 当然,只有在我对进行查询的应用程序进行身份验证的情况下。

So, is it possible to retrieve number of friends of a public profile on Facebook? 那么,是否有可能在Facebook上检索公开个人资料的朋友数量?

Nope. 不。

That says enough already: 那已经足够了:

“Can only lookup for the logged in user or the logged in user's friends that are users of your app.” 只能查找已登录用户或已登录用户的朋友(您的应用程序用户)。”

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

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