Notifications.send

From Facebook Developers Wiki

Jump to: navigation, search

Contents

[edit] Description

Sends a notification or request to a set of users. Notifications are items sent by an application to a user's notifications page in response to some sort of user activity within an application. Requests are actions initiated by the user (such as invitations to install an application or play a game) and appear on other users' request pages. You can also send messages to the logged-in user's notification page.

Your application can send a number of notifications or requests to a user in a day based on a number of metrics (or buckets). The number of notifications and the number of requests are determined separately. To get these numbers, use admin.getAllocation or check the Allocations tab on the Insights dashboard for your application in the Facebook Developer application.

Notifications sent to the notifications page for non-application users are subject to spam control. Read more information about how spamminess is measured. Additionally, any notification that you send on behalf of a user appears on that user's notifications page as a "sent notification."


[edit] Parameters

RequiredNameTypeDescription
required api_key string The application key associated with the calling application.
session_key string The session key of the logged in user.
call_id float The request's sequence number. Each successive call for any session must use a sequence number greater than the last. We suggest using the current time in milliseconds, such as PHP's microtime(true) function.
sig string An MD5 hash of the current request and your secret key, as described in the authentication guide.
v string This must be set to 1.0 to use this version of the API.
to_ids array Comma-separated list of recipient IDs. These must be either friends of the logged-in user or people who have added your application. To send a notification to the current logged-in user without a name prepended to the message, set to_ids to the empty string.
notification string FBML for the notifications page. Uses a stripped down version allowing only text and links.
optional format string Desired response format. Either XML (default) or JSON.
callback string Name of a function to call. This is primarily to enable cross-domain JavaScript requests using the <script> tag, also known as JSONP, and works with both the XML and JSON formats. The function will be called with the response passed as the parameter.


[edit] Example Queries

$facebook->api_client->notifications_send($uid, 'some info');


[edit] Example Return XML

<?xml version="1.0" encoding="UTF-8"?> <notifications_send_response xmlns="http://api.facebook.com/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://api.facebook.com/1.0/ http://api.facebook.com/1.0/facebook.xsd"> </notifications_send_response>


[edit] Response

The return value was previously used for the email-related part of this function, which has since been deprecated.


[edit] Error Codes

CodeDescription
1 An unknown error occurred. Please resubmit the request.
2 The service is not available at this time.
4 The application has reached the maximum number of requests allowed. More requests are allowed once the time window has completed.
5 The request came from a remote address not allowed by this application.
100 One of the parameters specified was missing or invalid.
101 The API key submitted is not associated with any known application.
102 The session key was improperly submitted or has reached its timeout. Direct the user to log in again to obtain another key.
103 The submitted call_id was not greater than the previous call_id for this session.
104 Incorrect signature.


[edit] Notes

  • If you are using an older version of facebookapi_php5_restlib.php or facebookapi_php4_restlib.php, then change line 256 (line 258 for PHP 4) in notifications_send from:
256: array('to_ids' => $to_ids, 'markup' => $markup, 'no_email' => $no_email));
to:
256: array('to_ids' => $to_ids, 'notification' => $markup));
This is needed to send the notification. Otherwise the script always returns Invalid Paramater.
  • The user name of the logged-in user is prepended to the notification. Your notification FBML should take this into account by starting with a verb. This does not happen if you set to_ids to be empty.
  • It appears that there is no way to tell when notifications fail due to to user not being a friend. Using the PHP API, null is returned either way. Bug 992 has been filed to track this issue.
You can work around this issue by generating and saving an infinite session key every time a user adds your application. You can then easily send notifications to any user at any time.


[edit] See Also

You can see a real world example of this method in the Footprints demo application. Go to Demos for more details and to download and install the demo apps.

Navigation