So let's say that you're building a complicated Facebook app that involves a user becoming an 'admin' in some way. For example, you want your user to login to the app, invite some friends and then interact with their friends inside of your app. At some point the question is going to arise, how will the users know that their friends have accepted the invite? Well the simple answer of course is that you rely on your users to return to the app to check if anyone else has signed up to it. But this is isn't 2004, apps are now plentiful and most are overlooked even if your user has taken the trouble to sign up in the first place. They get forgotten about. They become unloved. Poor little things.
So what's the solution? How do you get your users to return to your app without annoying the hell out of them? Periodically post stuff on their walls? Fill their newsfeeds with annoying anecdotes?
There's a simple and elegant solution that is often overlooked. If your user has invited friends to join the app, track the friend's facebook ID (store it off in your DB somewhere) and when the person finally joins, send off a quick notification to the original user.
I am of course talking about one of these...
It's unobtrusive and simple. Just send them a notification saying something like "Your friend Brian has accepted your invite. Play a game now!" and then link them off to your app. It's friendly, the person won't feel as though they're being spammed and users are more likely to return to your app.
There are a couple of assumptions that I'm going to have to make in order to show you how to do this. Firstly I have to presume that if you're building this complex an app that you know how to connect to Facebook using PHP and request both login and permissions from your users. If you're not sure how to do this, send me a comment below and I may blog about it in the future.
So here's the code that you'll want to fire off when the user's friend's facebook ID matches one that you have stored in your DB...
1. Set up your notification text and link
$notification_message = 'Brian has accepted your invite! Click here to play'; $notification_app_link = 'http://facebook.com/yourapp';
2. Set up a notification array using your app ID and Secret
$accessToken = $facebook->getAppId().'|'.$facebook->getApiSecret(); $notificationArray = array('access_token' => $accessToken, 'href' => $notification_app_link, 'template' => $notification_message);
3. Fire the notification
$fb_response = $facebook->api('/' . $user . '/notifications', 'POST', $notificationArray);
And that's it! Not really hard at all right? Use it, but remember please don't abuse it - if they remove notifications because you're overusing or spamming with them then everybody loses.
Hope that helps!