I want to build an app which generates a notification (like SMS -> mobile user will get a notification on his or her phone like while reciving a SMS) for a small range of users that are subscribing that notifications.
I have build an App and such a Community Page (I'm not very familar with Facebook).
Here is my code:
//PHP SDK
require 'include/facebook.php';
//Instant Facebook-Object
$facebook = new Facebook(array(
'appId' => '...',
'secret' => '...',
'cookie' => true,
));
$user = $facebook->getUser();
if ($user) {
try {
// Proceed knowing you have a logged in user who's authenticated.
$userData = $facebook->api('/me');
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}
// If a user haven't been loged in, so the user have to authorize
if (!$user) {
$loginUrl = $facebook->getLoginUrl(
array(
'scope' => 'publish_stream',
'redirect_uri' => 'http://my-hosting.url/'
)
);
header('Location: '.$loginUrl);
exit;
}
try {
$publishStream = $facebook->api("/$testid/feed", 'post', array(
'message' => 'Hello World',
'link' => 'http://www.example.org/',
'name' => 'Test',
'description' => 'Wohoo some great text.',
)
);
} catch (FacebookApiException $e) {
var_dump($e);
}
I'm playing with the $testid
it contains e.g. $user or community page ID.
In case of the user id I get the message on my wall but without any notification with is sad. If I change that to the community page I'll get an exception with this message:
(#210) User not visible
That seems that the community page is not allowed to to that. Well before I try to get that permission I would like to ask if this way is possible or if I'm just wasting my time.
I can think of mainly two ways of sending notifications to a user using the graph api, each one then splits to two.
1) Requests The requests are a part of the Social Channels and have two types:
2) Private messages If you send a private message then the user will get it as any other PM, which means that if the user has installed the facebook app on his mobile phone then he will be notified on the new PM.
You have two ways to send messages using the api: