facebookのFQLを使ってどんなデータが出せるのやら調べてみました。

ちなみにFQLとは、facebookサイト内で使えるSQLライクな言語「Facebook Query Language」のことです。
例えば、自分の友達のアイコンを全部取得するとか好きな子の写真を全部集めるとかそういったことができます。


FQLのページ(facebook公式)

Facebook Query Language (FQL)

まずは、テーブル一覧index可能なカラムをこちらで確認します。



FQLのテスト(facebook公式)

fql.query

FQLのテストができるところはないかと探してみたところ、facebookの開発者ページにありました。
facebookデベロッパ登録アプリ作成していないとできません。
※取得したいカラムによっては、その対象(ユーザ)がそのアプリからの情報取得を認証している必要があります。




  • 手順

1、query欄にテストしたいクエリーを入力する
2、コールメソッドを押す
3、右の大きなボックスに結果が返されます。



FQLの例

文法、参考にしてください。

usernameから各種情報取得のクエリ

SELECT uid,name, sex, pic,username FROM user WHERE username ="junnemoto"

uidから友達を取得のクエリ

SELECT uid1 FROM friend WHERE uid2='100001264187076'

友達の画像を取得するクエリ

SELECT pic,pic_big,pic_square FROM user WHERE uid='100001264187076'

サブクエリもできます!
私の友達の画像を全部取得するクエリ

SELECT pic FROM user WHERE uid in
(SELECT uid1 FROM friend WHERE uid2='100001264187076')

私がいいねを押したURLを取得するクエリ

SELECT url FROM object_url
    WHERE url <>"" AND id IN (SELECT object_id FROM like WHERE user_id=100001264187076)

私の情報を根こそぎ取得するクエリ

SELECT uid
,first_name
,middle_name
,last_name
,name
,pic_small
,pic_big
,pic_square
,pic
,affiliations
,profile_update_time
,timezone
,religion
,birthday
,birthday_date
,sex
,hometown_location
,meeting_sex
,meeting_for
,relationship_status
,significant_other_id
,political
,current_location
,activities
,interests
,is_app_user
,music
,tv
,movies
,books
,quotes
,about_me
,hs_info
,education_history
,work_history
,notes_count
,wall_count
,status
,has_added_app
,online_presence
,locale
,proxied_email
,profile_url
,email_hashes
,pic_small_with_logo
,pic_big_with_logo
,pic_square_with_logo
,pic_with_logo
,allowed_restrictions
,verified
,profile_blurb
,family
,username
,website
,is_blocked
,contact_email
,email
,third_party_id
FROM user WHERE uid='100001264187076'


追記

FQLのパーミッションについて。

emailアドレスなどカラムによっては認証がないと引き出せません。
そんなときは下記のURLに「」内を自分のアプリ用に調整してご利用下さい。

https://www.facebook.com/dialog/oauth?
     client_id=「YOUR_APP_ID」&redirect_uri=「YOUR_URL」&scope=「email,read_stream」

私がいいねを押したfacebookページのファン数を取得するクエリ

select page_id,name,fan_count from page where page_id in(select uid,page_id from page_fan where uid = 100001264187076) order by fan_count

参考:
URLについては
http://developers.facebook.com/docs/authentication/
パーミッションの名前については
http://developers.facebook.com/docs/authentication/permissions/