반응형

Facebook Query Language(FQL)
Advanced Topics > Facebook Query Language(FQL)

원문 : http://developers.facebook.com/docs/reference/fql/



 FQL 객체는 Graph API를 사용하여 FQL 쿼리들을 실행할 수 있습니다. Facebook Query Language,  또는 FQL 은, 여러분들이 Graph API 로 볼 수 있는 정보들을 질의하기 위한 SQL 형식의 인터페이스를 사용할 수 있게 해줍니다. FQL 은 Graph API 에서는 이용할 수 없는 몇가지 진보된 특징들을 제공하는데, 그 중에는 한 번 호출함을써 일괄처리하는 다중 질의들을 포함합니다.

Example

"SELECT uid2 FROM friend WHERE uid1=me()" 쿼리는 

GET /fql?q=SELECT+uid2+FROM+friend+WHERE+uid1=me()&access_token=...

를 실행합니다.


Read

여러분은  /fql?q=query 형태로 HTTP GET 요청을 보낼 수 있습니다. 여기서 query는 단일의 fql 쿼리 또는 여러 쿼리들의 JSON 코드형식 사전이 될 수 있습니다.

Query

쿼리들은 SELECT [fields] FROM [table] WHERE [conditions] 형식으로 되어 있습니다. SQL 과는 다르게 FQL의 FROM 문은 오직 한 가지 테이블만을 담을 수 있습니다. 여러분은 서브쿼리를 수행하기 위해서 SELECT 나 WHERE 절에서 IN 키워드를 사용할 수 있습니다, 그러나 그 서브쿼리들은 쿼리의 범위 밖에서는 참조 변수일 수 없을 것입니다. 여러분의 쿼리는 또한 인덱스를 수행할 수 있어야만 하는데,  아래 문서에 인덱스가능한 것으로 표시된 속성들은 질의할 수 있다는 것을 의미합니다.

FQL 은 간단한 수학, 기본적인 boolean 연산, AND 또는 NOT 은 논리적 연산자들, 그리고 ORDER BY 나 LIMIT 절들을 다룰 수 있습니다.

uid 를 처리하는 몇몇 질의들에 대해서는, 여러분은 로그인 한 사용자를 반환하는  me() 함수를 전할 수 있습니다. 예를 들면 :
SELECT name FROM user WHERE uid = me() 

사용할 수 있는 다른 함수들로는 now()strlen()substr() and strpos() 이 있습니다.

여기에는 활성화한 사용자와 친구들에 대한 모든 사용자 정보를 가져올 수 있는 서브쿼리의 예가 있습니다. :

SELECT uid, name, pic_square FROM user WHERE uid = me()
OR uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) 

Multi-Query

FQL 질의들의 한 묶음을 한 번 호출해서 처리하고 한 번에 데이터를 반환할 수 있습니다.

이 방법은 "queries" 라고 불리는 JSON 코드화된 사전을 실행하는데 각각의 쿼리들을 마치 한개의 간단한 쿼리처럼 정확하게 같은 문법을 사용합니다. 그러나, 이 방법은 좀 더 복잡한 질의들로 만들어지는 것을 허용합니다. 여러분은 한 개의 쿼리로부터 데이터를 가져올 수 있고 같은 호출 안의 다른 쿼리 안에서도 사용할 수 있습니다(가져온 값을 다른 쿼리에서 사용 가능함). WHERE 절은 후자의 쿼리에서는 추가적인데, 그것은 이미 가져온 데이터를 참조하기 때문입니다. 같은 호출에서 다른 쿼리 안의 특정 쿼리 결과를 참조하기 위해서는, #을 앞에 사용함으로써 FROM 절에서 이름을 명확하게 해야합니다. 

예를 들면, 여러분이 이벤트에 참석 중인 사용자에 대한 몇가지 데이터들을 보길 원한다고 해봅시다. 보통, 여러분은 한 줄에서 두 질의를 수행하려고 할 것입니다, 두번째 쿼리가 실행되기 전에 첫번째 쿼리의 결과를 기다리고 있습니다, 그것은 두번째 쿼리가 첫번째 쿼리의 데이터에 의존해 있기 때문입니다. 그러나 fql.multiquery 를 쓰면, 여러분은 동시에 그것을을 실행할 수 있고, 필요로 하는 결과를 모두 얻을 것입니다., fql.query 호출의 묶음을 실행하는 것보다 더 나은 성능을 여러분에게 줄 것입니다. 첫째로, 당신은 사용자 ID 와 각 참석자의 RSVP 상태를 얻을 필요가 있을 것입니다, 그래서 당신은 첫번째 질의를 명확히 할 수 있습니다. - query1 - 다음과 같이:
"query1":"SELECT uid, rsvp_status FROM event_member WHERE eid=12345678"

그 다음으로 참석자의 프로필 정보를 얻으려면(name, URL, 그리고 picture), 두 번째 쿼리를 만들어야만 합니다. – query2 – query1 으로부터의 결과를 참조합니다. 여러분은 query2 를 다음과 같이 명확하게 할 수 있습니다.:

"query2":"SELECT name, url, pic FROM profile WHERE id IN (SELECT uid FROM #query1)"

이방법 또한  batch.run. 을 호출한 fql.query의 묶음을 실행하는 것보다 더 나은 성능을 가실 수 있습니다. 


Sample

여기에 fql 질의를 수행하는 예제가 있습니다.

<?php $app_id = 'YOUR_APP_ID'; $app_secret = 'YOUR_APP_SECRET'; $my_url = 'POST_AUTH_URL'; $code = $_REQUEST["code"]; //auth user if(empty($code)) { $dialog_url = 'https://www.facebook.com/dialog/oauth?client_id=' . $app_id . '&redirect_uri=' . urlencode($my_url) ; echo("<script>top.location.href='" . $dialog_url . "'</script>"); } //get user access_token $token_url = 'https://graph.facebook.com/oauth/access_token?client_id=' . $app_id . '&redirect_uri=' . urlencode($my_url) . '&client_secret=' . $app_secret . '&code=' . $code; $access_token = file_get_contents($token_url); // Run fql query $fql_query_url = 'https://graph.facebook.com/' . '/fql?q=SELECT+uid2+FROM+friend+WHERE+uid1=me()' . '&' . $access_token; $fql_query_result = file_get_contents($fql_query_url); $fql_query_obj = json_decode($fql_query_result, true); //display results of fql query echo '<pre>'; print_r("query results:"); print_r($fql_query_obj); echo '</pre>'; // Run fql multiquery $fql_multiquery_url = 'https://graph.facebook.com/' . 'fql?q={"all+friends":"SELECT+uid2+FROM+friend+WHERE+uid1=me()",' . '"my+name":"SELECT+name+FROM+user+WHERE+uid=me()"}' . '&' . $access_token; $fql_multiquery_result = file_get_contents($fql_multiquery_url); $fql_multiquery_obj = json_decode($fql_multiquery_result, true); //display results of fql multiquery echo '<pre>'; print_r("multi query results:"); print_r($fql_multiquery_obj); echo '</pre>'; ?>



    Tables

    Query this table to return information about a photo album.

    Query this table to return read-only properties about an application.

    An FQL table containing the requests sent via an app to a user.

    Query this table to return information about a checkin. By default, this query returns the last 20 checkins and returns a maximum of 500 checkins.

    Query this table to obtain comments associated with one or more [fb:comments]

    The comments_info FQL table. Query this table to obtain XIDs for fb:comments objects associated with an application ID.

    Query this table to return a user's friends and the Facebook Pages to which the user is connected.

    Query this table to return information about a cookie.

    Query this table to return the application IDs for which the specified user is listed as a developer in the Developer application.

    The domain table provides a read-only mapping between domain names and ids.

    Query this table to return information about the admin of a domain.

    Query this table to return information about an event.

    Query this table to return information about a user's status for an event or see a list of events for a user.

    Query this table to return detailed information about a user's family.

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

    Query this table either to determine which users have sent friend requests to the logged-in user or to query whether a friend request has been sent from the logged-in user to a specific user.

    Query this table to return any friend lists owned by the specified user.

    Query this table to determine which users are members of a friend list.

    Query this table to return information about a group.

    Query this table to return information about the members of a group, or retrieve a list of groups of which a user is a member

    The insights table contains statistics about Applications, Pages and Domains

    Query this table to return the user IDs of users who like a given Facebook object (video, note, link, photo, or album).

    Query this table to return the links a user has posted.

    The link_stat table contains counts that show how users on Facebook are interacting with a given link.

    The mailbox_folder table contains information about a user's mailbox folders.

    Query this table to return information about messages in a thread.

    Query this table to return the notes the current user has written or to return details for a particular note.

    Query this table to get the notifications for the current session user, that is, any notification that appears on http://www.facebook.com/notifications.php.

    Query this table to return information about a URL in the Open Graph

    Query this table to return information about a Facebook Page.

    Query this table to return information about which Facebook Pages the user Admins.

    An FQL table that can be used to return a list of a users that are blocked from a Facebook Page.

    Query this table to return information about the user who likes a Facebook Page.

    Query this table to return the permissions the current user has granted to the app.

    Query this table to return more descriptive information about extended permissions.

    Query this table to return information about a photo.

    Query this table to return information about a photo tag.

    Query this table to return information about a place.

    Query this table to return a user's privacy setting for a given object_id.

    Query default privacy settings for a user for a particular app

    Query this table to return certain (typically publicly) viewable information for a profile.

    A Question as represented in FQL.

    An option for a question, as represented in FQL.

    The votes on a particular option for a question, as represented in FQL.

    Query this table to obtain reviews associated with an application, a user or both.

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

    Query this table to return standard information about a user, for use when you need analytic information only.

    Query this table to return one or more of a user's statuses.

    Query this table to return posts from a user's stream or the user's profile.

    Query this table to return a filter_key that can be used to query the stream FQL table, as seen through any content filters the user has available on Facebook.

    Query this table to return associations between users or Facebook Pages and the items they tag in status posts.

    Query this table to return information about message threads in a user's Inbox.

    Query this table to return the native strings (original, untranslated text in your application interface) and the translated strings for your application.

    This table can be used to access information about messages in the new Facebook messaging system.

    This table can be used to access information about threads in the new Facebook messaging system.

    This table should be used to access information about subscribe and unsubscribe actions performed on a thread in the new Facebook messaging system.

    This table should be used to access information about the number of threads in a folder in the new Facebook messaging system.

    An FQL table containing the Open Graph URLs that the current session user has Liked.

    Query this table to return detailed information from a user's profile.

    The video table contains information about videos.

    The video_tag table contains information about users tagged in videos.



    반응형

    + Recent posts