This information is as of July 25th. It was originally posted in another thread but I had confused general with announcement notifications so I am reposting here, with the hope it might clear up some confusions.
I've played around a lot with these Announcement Notifications and got them working. Here is what I've found.
The support for it has NOT been built into the PHP5 library yet. However I wrote my own function which you can copy and paste into your facebookapi_php5_restlib.php file.
Update as of July 30th:
Facebook seems to have updated their 'type' parameters on the notifications.send API call. The change:
"announcement" should now be sent as type "app_to_user"
"general" should now be sent as type "user_to_user"
/**
* Sends an announcement notification to the application users.
* @return (nothing)
*/
public function ¬ifications_send_announce($to_ids, $notification) {
return $this->call_method('facebook.notifications.send',
array('to_ids' => $to_ids, 'notification' => $notification, 'type' => 'app_to_user'));
}A notification can then be generated using code such as...
$userid = 123456789; //This can also be a comma separated list of UIDs $facebook->api_client->notifications_send_announce($userid, 'You have just received an announcement notification! Click <a href="http://www.apps.facebook.com/appname/">here</a> to go to my application.');
Now as far as who these can be sent to... I believe it is inherent in the name (announcement notification) that this type of notification can only be sent to users of your application. Also in my experience I've found it does not depend on whether the RECEIVING user has a session key or not (since these now expire in a max of 24 hours after the user first uses your application). It seems as if Facebook uses a separate determining method for whether the UID is actually a user of your application (maybe like a permanent list of all UIDs who've used you app? I'm not sure. But I've noticed I can still send an Announcement Notification even if the user hasn't used my application in the last 24 hours).
Furthermore, I haven't found a solid way to send these through API calls when a user is actually USING your application. I've only been able to send these without errors through a CRON script. I believe the reason lies in the php client. It seems to be sending session data to the API call when it shouldn't with announcement notifications, and as such, generates an error.
I speculated you might be able to send these if you put the php Announcement Notification code in a separate php file and AJAX called it from the page you want it to send from. The idea here is that the AJAXed php file will not have any session data attached to it and the API call will call correctly. This hasn't been tested, though.
Also one last point of interest. When a user receives an Announcement Notification, it does not have any kind of text pre-pended to the front of it. It simply displays your application icon next to the notification. This is in contrast to a user-to-user General Notification which pre-pends the name of the user who performed the action.
Here is a sample screenshot of a received Announcement Notification from my application:
Let me know if you've got any other questions.
-Mike
Last edited by mikeknoop (2008-07-30 14:27:07)
Offline
Nice post!
What was the limit on these? I remember something like 7 a week.
Offline
The starting limit is 7 Announcement Notifications per week. This metric is the default metric assigned to a new application. I noticed in my application, though, that Facebook seems to have assigned my initial Announcement Notification limit based on your current General Notification limits.
As an example, I had a limit of 50 General Notifications when this new profile was rolled out. When I checked my Announcement Notification limit, I noticed it started at 28 (bucket 11 out of 11, this is the max).
-Mike
Last edited by mikeknoop (2008-07-25 12:03:26)
Offline
mikeknoop wrote:
Let me know if you've got any other questions.
-Mike
this does not require an active facebook sessoin right, so it is not bound to any specific uid. so do you know how many uids can i put in the to_ids ? is there a limit?
Offline
I've got this error:
Fatal error: Uncaught exception 'FacebookRestClientException' with message 'Invalid parameter'
Offline
kevin3210 wrote:
mikeknoop wrote:
Let me know if you've got any other questions.
-Mikethis does not require an active facebook sessoin right, so it is not bound to any specific uid. so do you know how many uids can i put in the to_ids ? is there a limit?
You are correct, it is not bound from a specific UID, but rather your application. The limit of UIDs you can send to is specified by your specific application allocations. You can find this metric (along with all of your apps others) by going to your applications about page, then click Insights, an then click on the Allocations tab.
jeunz wrote:
I've got this error:
Fatal error: Uncaught exception 'FacebookRestClientException' with message 'Invalid parameter'
This was the error I referenced in the initial post about session keys. You can't call this API call from an active user session using the current version of the PHP client. Like I said, I was only able to get Announcement notifications working using a CRON script (these run from my server at a specified interval, and are never tied to a user session) but in theory you could AJAX load a separate PHP file that contains the notification call.
Your AJAX loaded Announcement Notification file might look something like...
<?php // some basic library functions include_once 'lib.php'; // this defines some of your basic setup include_once 'config.php'; include_once 'client/facebook.php'; $facebook = new Facebook($api_key, $secret); $uid = $_POST['uid']; $facebook = new Facebook($api_key, $secret); $facebook->api_client->notifications_send_announce($uid, 'You have received replies to your phone number request!'); echo "Announcement Notification sent."; ?>
That might work. What hasn't been tested is whether an AJAXed script with an API call will automatically pass session data to the API server. (If that were to happen, you would still get the error you do now, and the only solution would be to re-write part of the PHP client to not send this information in certain cases, such as when calling the Announcement Notification function).
-Mike
Offline
mikeknoop wrote:
kevin3210 wrote:
mikeknoop wrote:
Let me know if you've got any other questions.
-Mikethis does not require an active facebook sessoin right, so it is not bound to any specific uid. so do you know how many uids can i put in the to_ids ? is there a limit?
You are correct, it is not bound from a specific UID, but rather your application. The limit of UIDs you can send to is specified by your specific application allocations. You can find this metric (along with all of your apps others) by going to your applications about page, then click Insights, an then click on the Allocations tab.
the metric on the allocations page says how many announcements / week i can send to a user. not the number of uids i can put in to_ids parameter.
my question is how many max uids can i put in to_uids,can i put in a 100 , a million different udis?
Offline
Well the two values are related. You could put in as many UIDs as you want into that parameter (though due to technical limitations PHP might fail at 65535... not positive though). However if you attempt to send to more UIDs than your allocations allow you will receive Error Code #4 per http://wiki.developers.facebook.com/ind … tions.send
So the short answer is: as many as you want.
But realize to send without error it must be within your weekly allocation limit for your application.
-Mike
Offline
I tried this:
require_once('../facebook/client/facebook.php');
$facebook = new Facebook("XXXX","XXX");
$facebook->api_client->notifications_send_announce('721099688','blablabla...');
launched by my server with a cron... but I still have an error:
Uncaught exception 'FacebookRestClientException' with message 'Session key invalid or no longer valid
Last edited by jeunz (2008-07-25 13:49:46)
Offline
Somehow it's still passing a session key... do you think you could post the entire script, or was that it?
-Mike
Offline
It was the entire (test) script ^^ ![]()
Offline
Are you using the most up to date client? Try using this version of the PHP client:
http://svn.facebook.com/svnroot/platfor … n-changes/
-Mike
Offline
A few people have been asking about the number of UIDs you can send to in one call. To my knowledge there is no imposed limitation. This needs to be checked though.
My personal application uses a loop to call the function subsequent times so I haven't needed to use a comma separated UID list yet.
-Mike
Offline
Thanks it works fine with the new "client".
Offline
bien pelao, esto si funciona! thanks men works very good!
Offline
There is some talk about weird metrics and allocations being influenced by Announcement Notifications as of July 28th.
Please check it out here:
http://forum.developers.facebook.com/vi … 595#p91595
-Mike
Offline
thanks for all the helpful information.
I was wondering if someone knows the answer to this: can you send an announcement notification to someone who does not have the app? i understand you can send a general notification to your friends, but I'm trying to do this such that the recipient doesn't actually know who the message is from. i wouldn't do mass notifications, just targeted to a specific person who isn't necessarily friends with any of the app's users, and don't necessarily have it installed yet.
Last edited by curban (2008-07-28 19:54:01)
Offline
I'm almost certain the announcement notification has to be sent to an application user. This is how it's been quoted on all the developer's blog posts regarding Announcement Notifications, though I've never explicitly tried sending one to a non-app user.
EDIT: Tested this just for curiosity's sake. No deal, all Announcement Notifications have to be sent to an app user
-Mike
Last edited by mikeknoop (2008-07-29 22:01:16)
Offline
I'm trying to get this to work, but I'm unable to get any notifications to show up within my notifications tab:
$ret = $facebook->api_client->notifications_send_announce($facebook_id, '<fb:notif-subject>You have a new message!</fb:notif-subject><fb:notif-page>Test</fb:notif-page>');
When I run this, it returns to me the uid of the user I am sending it to. When I go to the notifications tab, I don't see any notifications at all.
On the right hand side it has "Applications You've Authorized" but mine isn't even an option and I am not sure where to authorize my app. Any ideas?
Offline
Well since you're not getting an error it seems to be calling correctly.
Have you "allowed" the application on your account? Using require_login()?
-Mike
Offline
I'm not sure exactly what you mean. When I do this:
$facebook = new Facebook($vals['api_key'], $vals['secret']); $user = $facebook->require_login();
It kills my external application.
Offline
Well a user needs to be authorized and must have logged into your application before in order to receive an announcement notification. If you can find out how to fix the login procedure to function correctly, the notifications should start appearing.
-Mike
Offline
So, the user has logged in multiple times. When the user accesses my application from facebook, this code works fine:
$facebook = new Facebook($vals['api_key'], $vals['secret']); $user = $facebook->require_login();
However, when I want to send a notifcation from an external app, I make the following call (using the users facebook id who has previously logged in):
$facebook = new Facebook($vals['api_key'], $vals['secret']); $ret = $facebook->api_client->notifications_send_announce($facebook_id, '<fb:notif-subject>You have a new message!</fb:notif-subject><fb:notif-page>Test</fb:notif-page>');
As I said before $ret is the uid of the user I am sending to, but I don't see the notification within facebook
Offline
Are you able to send Announcement Notifications in any other scenarios? I'm trying to narrow down the problem...
-Mike
Offline
So when I post a notification from within my facebook app, it runs correctly. Is there a way for an external application to send notifications or post to a users wall without that user being logged into facebook?
Offline