Tag Archive for 'app to user'

Facebook: Sending App to user notifications through Javascript

If you refer to facebook’s documentation at http://developers.facebook.com/docs/?u=facebook.jslib.FB.ApiClient.notifications_send, you will notice that there are no parameters to specify an app_to_user notification type. To achieve this, you have to use the callMethod from the apiClient.

Here is a code snippet on how this can be achieved in a Facebook Connect site.

<script src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php" type="text/javascript"></script>
 <script type="text/javascript">
	FB_RequireFeatures(["XFBML"], function(){ 
		FB.Facebook.init("API KEY", "relative_path_to/xd_receiver.htm"); 
		FB.Facebook.apiClient.callMethod("notifications_send",{to_ids:[000000000],notification:"hello",type:"app_to_user"},function(){alert("notification sent");});	
	});
</script>

This code sends a notification from the app to the specified user ids. When the notification is done, a javascript alert box tells us the task is completed.