Setting Status

Problem

I need to set the Facebook status of my users.

Solution

Use the Users.setStatus() method, which unfortunately isn’t supported in the PHP Client Library (see Adding Missing PHP Client Library Methods):

$result = $facebook->api_client->Users_setStatus('setting his status
using the API!',false);

The parameters, in order, are the status and whether or not to clear the status. Passing true for clear will ignore the status you pass in and leave it blank.

Discussion

You can set the status only for users who have given your application the status_update extended permission (see Extended Permissions for more information).

Users.setStatus() will also accept two additional parameters: a boolean called status_includes_verb, which will prepend “is” to the front of your status if you pass false, and a uid of the user for which you want to set the status (which is ignored for desktop apps and is required for web apps only if you don’t have a valid session).

Get Facebook Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.