3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Facebookの特定のユーザーの友人数を取得する(だけ)PHP

Last updated at Posted at 2014-10-24

0.前提

Facebookのプライバシー設定にて友人リストを公開する設定していないユーザーは取得できません。。
詳細は後述

1.アプリ登録

FQLを使用するためアプリ登録してApp ID、App Secretの値をメモる

参考:
Facebook アプリを作成する方法

2.ライブラリダウンロード

Facebook PHP SDK
のライブラリを使うのでダウンロード

srcのフォルダのみ(base_facebook.php、facebook.php、fb_ca_chain_bundle.crt)使用する

3.実装

App ID、App Secretを以下に打ち込む

単数ユーザーの場合

require_once("src/facebook.php");

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

$result = $facebook->api(array(
    'method' => 'fql.query',
    'query' => 'SELECT friend_count FROM user WHERE uid = xxxx',
));

echo $result[0]["friend_count"];

複数ユーザーの場合

require_once("src/facebook.php");

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


$results = $facebook->api(array(
    'method' => 'fql.multiquery',
    'queries' => array(
        'query1' => 'SELECT friend_count FROM user WHERE uid = xxxx',
        'query2' => 'SELECT friend_count FROM user WHERE uid = xxxx',
    ),
));

echo $results[0]["fql_result_set"][0]["friend_count"];
echo $results[1]["fql_result_set"][0]["friend_count"];

以上

 
 

Facebookプライバシー設定(友人リスト)について

以下より「プライバシー設定編集」をクリック
スクリーンショット_2014_10_24_12_35-2.png

 
以下で公開になっていない人は取得できない〜
スクリーンショット 2014-10-24 15.31.37.png

参考

FQLで関連する複数クエリを実行する
http://qiita.com/cognitom/items/fec2fec6cb3bf5ab0cce

Graph API Explorer
https://developers.facebook.com/tools/explorer

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?