Facebook Cookbook - Jay Goldman [161]
These instructions are for the PHP 5 version of the Client Library, but you should be able to apply them to the PHP 4 version as well:
Back up the copy of facebookapi_php5_restlib.php on your server, just in case we break something. You could also install them into an entirely new file and include it too, so that you don’t have to remember to make the same changes in future versions of the Client Library.
Open the nonbackup version in a text editor.
You can either insert all the new methods in one group, or you can find the right place in the file to insert them so that they’re with the related functions that the Client Library does include. I recommend the latter, so scroll down to line 596 and insert these two functions:
/**
* Creates a new Photo album
* @param string $name : name of the new album
* @param string $location : location of the new album
* @param string $description : description of the new album
* @param int $uid : album creator. null for session user
* @return array
*/
public function &photos_createAlbum($name, $location, $description, $uid=null){
return $this->call_method('facebook.photos.createAlbum',
array('name' => $name,
'location' => $location,
'description' => $description,
'uid' => $uid));
}
/**
* Adds Tags to a Photos
* @param int $pid : Photo ID of the target Photo
* @param int $tag_uid : uid of the user being tagged (or tag_text, not both)
* @param string $tag_text : text being tagged (or tag_uid, not both)
* @param float $x : x location of the tag box
* @param float $y : y location of the tag box
* @param string $tags : JSON formatted array of tags
* @param int $owner_uid : uid of the Photo owner. null for session user
* @return boolean
*/
public function &photos_addTag($pid, $tag_uid, $tag_text, $x, $y, $tags, $owner_uid){
return $this->call_method('facebook.photos.addTag',
array('pid' => $pid,
'tag_uid' => $tag_uid,
'tag_text' => $tag_text,
'x' => $x,
'y' => $y,
'tags' => $tags,
'owner_uid' => $owner_uid));
}
Scroll down to line 626 and insert these two functions:
/**
* Returns whether or not the user has a requested extended permission
* @param string $ext_perm : name of the extended permission to check
* @param int $uid : optional uid to check for. null for session user
* @return boolean
*/
public function &users_hasAppPermission($ext_perm,$uid=null) {
return $this->call_method('facebook.users.hasAppPermission',
array('ext_perm' => $ext_perm, 'uid' => $uid));
}
/**
* Sets the user's status
* @param string $status : The status message to set
* @param boolean $clear : Set to true to clear the status
* @param boolean $status_includes_verb : If set to false, "is" will be prepended
* @param int $uid : uid of the target user. null for session user
* @return boolean
*/
public function &users_setStatus($status, $clear, $status_includes_verb, $uid=null) {
return $this->call_method('facebook.users.setStatus',
array('status' => $status,
'clear' => $clear,
'status_includes_verb' => $status_includes_verb,
'uid' => $uid));
}
Discussion
I actually opened a bug for this situation in Facebook’s Bugzilla system, so it will hopefully get resolved in the future, and then you can use this recipe to line your birdcage.
Error Codes
Problem
My API calls don’t work! I’m getting errors back!
Solution
Don’t panic! 100- and 200-class errors are Facebook’s way of telling you that there’s something wrong with your API calls. The possible error codes are listed in Table 9-9.
Table 9-9. API error codes
Error code
Description
1
An unknown error occurred. Please resubmit the request.