Connect/Accessing User Data and Privacy Settings

From Facebook Developer Wiki

Jump to: navigation, search

Please read Understanding User Data and Privacy for more information about what information you have access to at any time, and how you can use it in your application.

There are three different ways in which you can access data about users to incorporate into your website or application.

  1. FQL – Facebook supports a SQL-like query language to access data directly about users.
  2. API methods – API methods can be called from any language using a client library.
  3. FBML/XFBML - Facebook supports a tag language that can be inserted into the HTML of your application or website to dynamically render data.

Contents

Understanding Sessions

Every API or FQL call will include a session parameter for the user who is currently viewing your site or application. The session key will determine exactly which information will be returned based on what the viewing or active user has access to see. If the current viewer is not signed in, you can use "null" as the session parameter and get information available to everyone. When you use FBML, this is handled automatically on your behalf.

You can access most all information for a user of your application when you have an active session for that user, and a limited amount of data that is considered publicly viewable if you do not have an active session. For data about other users that you wish to display to an active user, you must request this using the session key of the active user which will determine what information is available for that user to view. Friends usually have greater access to each other’s information than strangers.

Methods of Data Access

Using FQL

Facebook supports a SQL-like query language called FQL to let you access data about a user. This can often be easier to use than the API methods, particularly if you want to do complex queries such as requesting data about multiple people at once. Please note that the a session is required with each FQL query – you will only receive certain data if you have an active session and if the user's active session has access to view that information. You can use "null" if you are accessing data for a user who does not have an active session, or for a non-Facebook user.

FQL query example:

SELECT name FROM user WHERE uid = 211606

Frequently used FQL tables for accessing user data include:

  • user – returns just about all information that may appear on a user's profile on Facebook. Any information returned from this table may be used for display – but only in the context of the active session you are calling this with. You specify the fields you want returned with this request. If you want to determine if information about a user can be displayed publicly, to non-friends or non-Facebook users, you can call this method without an active session and returned data is considered publicly displayable. (viewable but not storable).
  • friend – returns the list of friend IDs for a user. If you are calling this for a user who is not the active user, the information returned will be subject to the privacy of the target user and whether the active user can view the friends.
  • Stream – returns the stream for an active user (requires user to first grant the read_stream extended permission).
  • standard_user_info – returns a limited set of fields for users who have authorized your application or website. The fields returned are: name, first_name, last_name, birthday, sex, locale, timezone, affiliations (regional only), profile_url, and proxied_email. This method can be called anytime without a session key. Data returned may only be used for your internal analytics and not used for display to any other users.

API Methods

The Facebook API can be called from any language using a client library, or accessing our services directly via methods.

Frequently used API methods for accessing user data include:

API Example:

$facebook->api_client->users_getInfo($uid, 'name');

Read about more API methods.

FBML / XFBML

Facebook supports a tag language that can be inserted into the HTML of your application or website. With these tags, Facebook will properly fill in the information at the time of render based on the viewing user’s session. For example, if you try to show the active user’s name or picture, that will be filled in at render time. But if you try to show the name of a user who has their information private, and the viewer cannot see it, “Facebook User” will be filled in instead. All of this is handled for you behind the scenes.

For more information, read:

FBML/XFBML example:

<fb:name uid=211606>
reference