Communicating with Users via Email in Facebook
Facebook will stop notification system for Application soon. That means facebook application will not send notification to its users. Instead this facebook inspires developer to send email from their application to their users. But a application couldn’t send email until user specifically provide permission. And this is one of the extended permission of facebook.
If you want to know how to prompt user for extended permission you can see my previous article http://thinkdiff.net/facebook/prompt-for-extended-permission-in-facebook-app/
In order for your application or site to get a user’s email address you have to do the following tasks:
- Configure your email domain in the application setting
- Request the permission from the user
- If the user grants your application or site the email permission, you can query for the email address
In the following figure you’ll see the email domain option. Here you’ve to provide the domain name that you’ll use in your reply-to option in mail when you’ll send mail to user from your app. So if you want reply-to field would be firstname.lastname@example.org then you should place temp.com in the field.
The interesting this is that, currently if you configure this field and save, facebook shows a message at top of your application.
If user give email permission you can retrieve user’s email by the following way. You can either use the FQL query or direct call to FB api
$query = "SELECT email FROM user WHERE uid="$uid"; $result = $facebook->api_client->fql_query($query);
$user_details = $facebook->api_client->users_getInfo($uid, 'email'); $user_email = $user_details['email'];
But keep in mind that you must provide a link in every email message you send that lets your users unsubscribe from email. If a user unsubscribed, you have to call auth.revokeExtendedPermission and stop sending the user email.