Facebook recently re-introduced app-to-user notifications on the Graph API, allowing developers to notify app users of events easily. This is an alternative to sending the user emails, and doesn’t required any additional permissions. Facebook controls the notifications so developers don’t use it to spam – something that happened with the old API.
If the notification is hidden / marked as spam by users, it will slowly be disabled for your app. Note that the API is currently in beta so it is subject to change. The Notifications API is only available to Canvas / Fan Page applications hosted on apps.facebook.com.
Using the new notifications API is very simple, and only required an app access_token
. As long as the user has your app installed, you are free to notify them about in-app events. Here’s how to make the API call:
The $response
will be a boolean value indicating success or failure.
The template
can be plain-text, like the example above, or use Facebook IDs, like “{60506094} sent you a message
“.
The href
parameter will always point to your App Canvas Page; you just need to specify a relative path to your page.
The access_token
is your app access_token, made up of your application ID, a pipe, and your applications secret:
$app_access_token = $app_id . '|' . $app_secret;