Attaches an handler to an event and invokes your callback when the event fires.
For example, suppose you want to record Likes in your database whenever a button is clicked:
FB.Event.subscribe('edge.create',
function(response) {
alert('You liked the URL: ' + response);
}
);
Or be notified when the session changes
FB.Event.subscribe('auth.authResponseChange', function(response) {
alert('The status of the session is: ' + response.status);
});
In both of these cases, you would replace the alert() with your handling code.
Global Events to which you can subscribe:
unknown to connectedThe response object passed into the callback function for these events looks like the following:
{
status: "", /* Current status of the session */
authResponse: { /* Information about the current session */
userID: "" /* String representing the current user's ID */
signedRequest: "", /* String with the current signedRequest */
expiresIn: "", /* UNIX time when the session expires */
accessToken: "", /* Access token of the user */
}
}
See Response and Session Objects section in the FB.getLoginStatus documentation for more information.
NOTE: auth.statusChange() does not have a 'status' field.
{
status: "", /* Current status of the session */
}
"http://www.example.com/login.php"
""
"http://www.example.com/article1.php"
"http://www.example.com/article2.php"
{
href: "", /* Open Graph URL of the Comment Plugin */
commentID: "", /* The commentID of the new comment */
}
{
href: "", /* Open Graph URL of the Comment Plugin */
commentID: "", /* The commentID of the deleted comment */
}
"http://www.example.com/article1.php"
For most cases, you will want to subscribe to auth.authResponseChange rather than auth.statusChange. The response is returned as a javascript array, not encoded as JSON.
Note that for some cases, the value of response is unkeyed, but when more than one variable is returned, it contains the appropriate keys.
You can subscribe multiple callbacks to one event using different function names.
| Name | Type | Description |
|---|---|---|
| name | String | Name of the event. |
| cb | Function | The handler function. |