ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/facebook/trunk/facebookapi_php5_restlib.php
Revision: 959
Committed: 2007-11-13T15:22:57-08:00 (17 years, 7 months ago) by douglas
File size: 54991 byte(s)
Log Message:
Merged with 2007-11-06!

File Contents

# User Rev Content
1 douglas 943 <?php
2 douglas 946 # vim: expandtab shiftwidth=2 tabstop=2
3     #
4     # Modified to use JSON when $json is set to true.
5     #
6     # Douglas Thrift
7     #
8     # $Id$
9 douglas 943 //
10     // +---------------------------------------------------------------------------+
11 douglas 945 // | Facebook Platform PHP5 client |
12 douglas 943 // +---------------------------------------------------------------------------+
13 douglas 945 // | Copyright (c) 2007 Facebook, Inc. |
14 douglas 943 // | All rights reserved. |
15     // | |
16     // | Redistribution and use in source and binary forms, with or without |
17     // | modification, are permitted provided that the following conditions |
18     // | are met: |
19     // | |
20     // | 1. Redistributions of source code must retain the above copyright |
21     // | notice, this list of conditions and the following disclaimer. |
22     // | 2. Redistributions in binary form must reproduce the above copyright |
23     // | notice, this list of conditions and the following disclaimer in the |
24     // | documentation and/or other materials provided with the distribution. |
25     // | |
26     // | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
27     // | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
28     // | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
29     // | IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
30     // | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
31     // | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
32     // | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
33     // | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
34     // | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
35     // | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
36     // +---------------------------------------------------------------------------+
37     // | For help with this library, contact developers-help@facebook.com |
38     // +---------------------------------------------------------------------------+
39     //
40    
41     class FacebookRestClient {
42     public $secret;
43     public $session_key;
44     public $api_key;
45     public $friends_list; // to save making the friends.get api call, this will get prepopulated on canvas pages
46     public $added; // to save making the users.isAppAdded api call, this will get prepopulated on canvas pages
47 douglas 946 public $json;
48 douglas 943
49     /**
50     * Create the client.
51 douglas 959 * @param string $session_key if you haven't gotten a session key yet, leave
52     * this as null and then set it later by just
53     * directly accessing the $session_key member
54 douglas 943 * variable.
55     */
56     public function __construct($api_key, $secret, $session_key=null) {
57     $this->secret = $secret;
58     $this->session_key = $session_key;
59     $this->api_key = $api_key;
60     $this->last_call_id = 0;
61     $this->server_addr = Facebook::get_facebook_url('api') . '/restserver.php';
62     if ($GLOBALS['facebook_config']['debug']) {
63     $this->cur_id = 0;
64     ?>
65     <script type="text/javascript">
66     var types = ['params', 'xml', 'php', 'sxml'];
67     function toggleDisplay(id, type) {
68     for each (var t in types) {
69     if (t != type || document.getElementById(t + id).style.display == 'block') {
70     document.getElementById(t + id).style.display = 'none';
71     } else {
72     document.getElementById(t + id).style.display = 'block';
73     }
74     }
75     return false;
76     }
77     </script>
78     <?php
79     }
80     }
81    
82     /**
83     * Returns the session information available after current user logs in.
84 douglas 959 * @param string $auth_token the token returned by auth_createToken or
85 douglas 943 * passed back to your callback_url.
86     * @return assoc array containing session_key, uid
87     */
88     public function auth_getSession($auth_token) {
89     $result = $this->call_method('facebook.auth.getSession', array('auth_token'=>$auth_token));
90     $this->session_key = $result['session_key'];
91     if (isset($result['secret']) && $result['secret']) {
92     // desktop apps have a special secret
93     $this->secret = $result['secret'];
94     }
95     return $result;
96     }
97    
98     /**
99     * Returns events according to the filters specified.
100 douglas 959 * @param int $uid Optional: User associated with events.
101 douglas 943 * A null parameter will default to the session user.
102     * @param array $eids Optional: Filter by these event ids.
103     * A null parameter will get all events for the user.
104 douglas 959 * @param int $start_time Optional: Filter with this UTC as lower bound.
105 douglas 943 * A null or zero parameter indicates no lower bound.
106 douglas 959 * @param int $end_time Optional: Filter with this UTC as upper bound.
107 douglas 943 * A null or zero parameter indicates no upper bound.
108     * @param string $rsvp_status Optional: Only show events where the given uid
109     * has this rsvp status. This only works if you have specified a value for
110     * $uid. Values are as in events.getMembers. Null indicates to ignore
111     * rsvp status when filtering.
112     * @return array of events
113     */
114     public function events_get($uid, $eids, $start_time, $end_time, $rsvp_status) {
115     return $this->call_method('facebook.events.get',
116     array(
117     'uid' => $uid,
118     'eids' => $eids,
119 douglas 959 'start_time' => $start_time,
120 douglas 943 'end_time' => $end_time,
121     'rsvp_status' => $rsvp_status));
122     }
123    
124     /**
125     * Returns membership list data associated with an event
126     * @param int $eid : event id
127     * @return assoc array of four membership lists, with keys 'attending',
128     * 'unsure', 'declined', and 'not_replied'
129     */
130     public function events_getMembers($eid) {
131     return $this->call_method('facebook.events.getMembers',
132     array('eid' => $eid));
133     }
134    
135     /**
136     * Makes an FQL query. This is a generalized way of accessing all the data
137     * in the API, as an alternative to most of the other method calls. More
138     * info at http://developers.facebook.com/documentation.php?v=1.0&doc=fql
139     * @param string $query the query to evaluate
140     * @return generalized array representing the results
141     */
142     public function fql_query($query) {
143     return $this->call_method('facebook.fql.query',
144     array('query' => $query));
145     }
146    
147 douglas 959 public function feed_publishStoryToUser($title, $body,
148 douglas 943 $image_1=null, $image_1_link=null,
149     $image_2=null, $image_2_link=null,
150     $image_3=null, $image_3_link=null,
151 douglas 950 $image_4=null, $image_4_link=null) {
152 douglas 943 return $this->call_method('facebook.feed.publishStoryToUser',
153     array('title' => $title,
154     'body' => $body,
155     'image_1' => $image_1,
156     'image_1_link' => $image_1_link,
157     'image_2' => $image_2,
158     'image_2_link' => $image_2_link,
159     'image_3' => $image_3,
160     'image_3_link' => $image_3_link,
161     'image_4' => $image_4,
162 douglas 950 'image_4_link' => $image_4_link));
163 douglas 943 }
164 douglas 959
165     public function feed_publishActionOfUser($title, $body,
166 douglas 943 $image_1=null, $image_1_link=null,
167     $image_2=null, $image_2_link=null,
168     $image_3=null, $image_3_link=null,
169 douglas 950 $image_4=null, $image_4_link=null) {
170 douglas 943 return $this->call_method('facebook.feed.publishActionOfUser',
171     array('title' => $title,
172     'body' => $body,
173     'image_1' => $image_1,
174     'image_1_link' => $image_1_link,
175     'image_2' => $image_2,
176     'image_2_link' => $image_2_link,
177     'image_3' => $image_3,
178     'image_3_link' => $image_3_link,
179     'image_4' => $image_4,
180 douglas 950 'image_4_link' => $image_4_link));
181 douglas 943 }
182    
183 douglas 951 public function feed_publishTemplatizedAction($actor_id, $title_template, $title_data,
184     $body_template, $body_data, $body_general,
185     $image_1=null, $image_1_link=null,
186     $image_2=null, $image_2_link=null,
187     $image_3=null, $image_3_link=null,
188     $image_4=null, $image_4_link=null,
189 douglas 956 $target_ids='') {
190 douglas 951 return $this->call_method('facebook.feed.publishTemplatizedAction',
191     array('actor_id' => $actor_id,
192     'title_template' => $title_template,
193 douglas 953 'title_data' => is_array($title_data) ? json_encode($title_data) : $title_data,
194 douglas 951 'body_template' => $body_template,
195 douglas 953 'body_data' => is_array($body_data) ? json_encode($body_data) : $body_data,
196 douglas 951 'body_general' => $body_general,
197     'image_1' => $image_1,
198     'image_1_link' => $image_1_link,
199     'image_2' => $image_2,
200     'image_2_link' => $image_2_link,
201     'image_3' => $image_3,
202     'image_3_link' => $image_3_link,
203     'image_4' => $image_4,
204 douglas 952 'image_4_link' => $image_4_link,
205 douglas 951 'target_ids' => $target_ids));
206     }
207    
208 douglas 943 /**
209     * Returns whether or not pairs of users are friends.
210     * Note that the Facebook friend relationship is symmetric.
211     * @param array $uids1: array of ids (id_1, id_2,...) of some length X
212     * @param array $uids2: array of ids (id_A, id_B,...) of SAME length X
213     * @return array of uid pairs with bool, true if pair are friends, e.g.
214     * array( 0 => array('uid1' => id_1, 'uid2' => id_A, 'are_friends' => 1),
215 douglas 959 * 1 => array('uid1' => id_2, 'uid2' => id_B, 'are_friends' => 0)
216 douglas 943 * ...)
217     */
218     public function friends_areFriends($uids1, $uids2) {
219     return $this->call_method('facebook.friends.areFriends',
220     array('uids1'=>$uids1, 'uids2'=>$uids2));
221     }
222 douglas 959
223 douglas 943 /**
224     * Returns the friends of the current session user.
225     * @return array of friends
226     */
227     public function friends_get() {
228     if (isset($this->friends_list)) {
229     return $this->friends_list;
230     }
231     return $this->call_method('facebook.friends.get', array());
232     }
233 douglas 959
234 douglas 943 /**
235     * Returns the friends of the session user, who are also users
236     * of the calling application.
237     * @return array of friends
238     */
239     public function friends_getAppUsers() {
240     return $this->call_method('facebook.friends.getAppUsers', array());
241     }
242    
243     /**
244     * Returns groups according to the filters specified.
245 douglas 959 * @param int $uid Optional: User associated with groups.
246 douglas 943 * A null parameter will default to the session user.
247     * @param array $gids Optional: group ids to query.
248     * A null parameter will get all groups for the user.
249     * @return array of groups
250     */
251     public function groups_get($uid, $gids) {
252     return $this->call_method('facebook.groups.get',
253     array(
254     'uid' => $uid,
255     'gids' => $gids));
256     }
257    
258     /**
259     * Returns the membership list of a group
260     * @param int $gid : Group id
261 douglas 959 * @return assoc array of four membership lists, with keys
262 douglas 943 * 'members', 'admins', 'officers', and 'not_replied'
263     */
264     public function groups_getMembers($gid) {
265     return $this->call_method('facebook.groups.getMembers',
266     array('gid' => $gid));
267     }
268    
269     /**
270     * Returns the outstanding notifications for the session user.
271 douglas 959 * @return assoc array of
272     * notification count objects for 'messages', 'pokes' and 'shares',
273 douglas 943 * a uid list of 'friend_requests', a gid list of 'group_invites',
274     * and an eid list of 'event_invites'
275     */
276     public function notifications_get() {
277     return $this->call_method('facebook.notifications.get', array());
278     }
279    
280     /**
281     * Sends an email notification to the specified user.
282     * @return string url which you should send the logged in user to to finalize the message.
283     */
284     public function notifications_send($to_ids, $notification, $email='') {
285     return $this->call_method('facebook.notifications.send',
286     array('to_ids' => $to_ids, 'notification' => $notification, 'email' => $email));
287     }
288    
289     /**
290 douglas 959 * Returns the requested info fields for the requested set of pages
291     * @param array $page_ids an array of page ids
292     * @param array $fields an array of strings describing the info fields desired
293     * @param int $uid Optionally, limit results to pages of which this user is a fan.
294     * @param string type limits results to a particular type of page.
295     * @return array of pages
296 douglas 943 */
297 douglas 959 public function pages_getInfo($page_ids, $fields, $uid, $type) {
298     return $this->call_method('facebook.pages.getInfo', array('page_ids' => $page_ids, 'fields' => $fields, 'uid' => $uid, 'type' => $type));
299 douglas 943 }
300    
301     /**
302 douglas 959 * Returns true if logged in user is an admin for the passed page
303     * @param int $page_id target page id
304     * @return boolean
305     */
306     public function pages_isAdmin($page_id) {
307     return $this->call_method('facebook.pages.isAdmin', array('page_id' => $page_id));
308     }
309    
310     /**
311     * Returns whether or not the page corresponding to the current session object has the app installed
312     * @return boolean
313     */
314     public function pages_isAppAdded() {
315     if (isset($this->added)) {
316     return $this->added;
317     }
318     return $this->call_method('facebook.pages.isAppAdded', array());
319     }
320    
321     /**
322     * Returns true if logged in user is a fan for the passed page
323     * @param int $page_id target page id
324     * @param int $uid user to compare. If empty, the logged in user.
325     * @return bool
326     */
327     public function pages_isFan($page_id, $uid) {
328     return $this->call_method('facebook.pages.isFan', array('page_id' => $page_id, 'uid' => $uid));
329     }
330    
331     /**
332 douglas 943 * Returns photos according to the filters specified.
333     * @param int $subj_id Optional: Filter by uid of user tagged in the photos.
334 douglas 959 * @param int $aid Optional: Filter by an album, as returned by
335 douglas 943 * photos_getAlbums.
336 douglas 959 * @param array $pids Optional: Restrict to a list of pids
337     * Note that at least one of these parameters needs to be specified, or an
338 douglas 943 * error is returned.
339     * @return array of photo objects.
340     */
341     public function photos_get($subj_id, $aid, $pids) {
342 douglas 959 return $this->call_method('facebook.photos.get',
343 douglas 943 array('subj_id' => $subj_id, 'aid' => $aid, 'pids' => $pids));
344     }
345    
346     /**
347     * Returns the albums created by the given user.
348     * @param int $uid Optional: the uid of the user whose albums you want.
349     * A null value will return the albums of the session user.
350     * @param array $aids Optional: a list of aids to restrict the query.
351     * Note that at least one of the (uid, aids) parameters must be specified.
352     * @returns an array of album objects.
353     */
354     public function photos_getAlbums($uid, $aids) {
355 douglas 959 return $this->call_method('facebook.photos.getAlbums',
356 douglas 943 array('uid' => $uid,
357     'aids' => $aids));
358     }
359    
360     /**
361     * Returns the tags on all photos specified.
362     * @param string $pids : a list of pids to query
363     * @return array of photo tag objects, with include pid, subject uid,
364     * and two floating-point numbers (xcoord, ycoord) for tag pixel location
365     */
366     public function photos_getTags($pids) {
367 douglas 959 return $this->call_method('facebook.photos.getTags',
368 douglas 943 array('pids' => $pids));
369     }
370    
371     /**
372     * Returns the requested info fields for the requested set of users
373 douglas 959 * @param array $uids an array of user ids
374 douglas 943 * @param array $fields an array of strings describing the info fields desired
375     * @return array of users
376     */
377     public function users_getInfo($uids, $fields) {
378     return $this->call_method('facebook.users.getInfo', array('uids' => $uids, 'fields' => $fields));
379     }
380    
381     /**
382     * Returns the user corresponding to the current session object.
383     * @return integer uid
384     */
385 douglas 959 public function users_getLoggedInUser() {
386 douglas 943 return $this->call_method('facebook.users.getLoggedInUser', array());
387     }
388    
389 douglas 959
390     /**
391     * Returns whether or not the user corresponding to the current session object has the app installed
392     * @return boolean
393 douglas 943 */
394     public function users_isAppAdded() {
395     if (isset($this->added)) {
396     return $this->added;
397     }
398     return $this->call_method('facebook.users.isAppAdded', array());
399     }
400    
401     /**
402     * Sets the FBML for the profile of the user attached to this session
403 douglas 959 * @param string $markup The FBML that describes the profile presence of this app for the user
404     * @param int $uid The user
405     * @param string $profile Profile FBML
406     * @param string $profile_action Profile action FBML
407     * @param string $mobile_profile Mobile profile FBML
408 douglas 943 * @return array A list of strings describing any compile errors for the submitted FBML
409     */
410 douglas 959 function profile_setFBML($markup, $uid = null, $profile='', $profile_action='', $mobile_profile='') {
411     return $this->call_method('facebook.profile.setFBML', array('markup' => $markup,
412     'uid' => $uid,
413     'profile' => $profile,
414     'profile_action' => $profile_action,
415     'mobile_profile' => $mobile_profile));
416 douglas 943 }
417    
418     public function profile_getFBML($uid) {
419     return $this->call_method('facebook.profile.getFBML', array('uid' => $uid));
420     }
421    
422     public function fbml_refreshImgSrc($url) {
423     return $this->call_method('facebook.fbml.refreshImgSrc', array('url' => $url));
424     }
425    
426     public function fbml_refreshRefUrl($url) {
427     return $this->call_method('facebook.fbml.refreshRefUrl', array('url' => $url));
428     }
429    
430     public function fbml_setRefHandle($handle, $fbml) {
431     return $this->call_method('facebook.fbml.setRefHandle', array('handle' => $handle, 'fbml' => $fbml));
432     }
433    
434 douglas 956 /**
435     * Get all the marketplace categories
436     *
437     * @return array A list of category names
438     */
439     function marketplace_getCategories() {
440     return $this->call_method('facebook.marketplace.getCategories', array());
441     }
442    
443     /**
444     * Get all the marketplace subcategories for a particular category
445     *
446     * @param category The category for which we are pulling subcategories
447     * @return array A list of subcategory names
448     */
449     function marketplace_getSubCategories($category) {
450     return $this->call_method('facebook.marketplace.getSubCategories', array('category' => $category));
451     }
452    
453     /**
454     * Get listings by either listing_id or user
455     *
456     * @param listing_ids An array of listing_ids (optional)
457     * @param uids An array of user ids (optional)
458     * @return array The data for matched listings
459     */
460     function marketplace_getListings($listing_ids, $uids) {
461     return $this->call_method('facebook.marketplace.getListings', array('listing_ids' => $listing_ids, 'uids' => $uids));
462     }
463    
464     /**
465     * Search for Marketplace listings. All arguments are optional, though at least
466     * one must be filled out to retrieve results.
467     *
468     * @param category The category in which to search (optional)
469     * @param subcategory The subcategory in which to search (optional)
470     * @param query A query string (optional)
471     * @return array The data for matched listings
472     */
473     function marketplace_search($category, $subcategory, $query) {
474     return $this->call_method('facebook.marketplace.search', array('category' => $category, 'subcategory' => $subcategory, 'query' => $query));
475     }
476    
477     /**
478     * Remove a listing from Marketplace
479     *
480     * @param listing_id The id of the listing to be removed
481     * @param status 'SUCCESS', 'NOT_SUCCESS', or 'DEFAULT'
482     * @return bool True on success
483     */
484     function marketplace_removeListing($listing_id, $status='DEFAULT') {
485 douglas 959 return $this->call_method('facebook.marketplace.removeListing',
486     array('listing_id'=>$listing_id,
487 douglas 956 'status'=>$status));
488     }
489    
490     /**
491     * Create/modify a Marketplace listing for the loggedinuser
492 douglas 959 *
493 douglas 956 * @param int listing_id The id of a listing to be modified, 0 for a new listing.
494     * @param show_on_profile bool Should we show this listing on the user's profile
495 douglas 959 * @param listing_attrs array An array of the listing data
496 douglas 956 * @return int The listing_id (unchanged if modifying an existing listing)
497     */
498     function marketplace_createListing($listing_id, $show_on_profile, $attrs) {
499 douglas 959 return $this->call_method('facebook.marketplace.createListing',
500     array('listing_id'=>$listing_id,
501     'show_on_profile'=>$show_on_profile,
502     'listing_attrs'=>json_encode($attrs)));
503 douglas 956 }
504    
505    
506     /////////////////////////////////////////////////////////////////////////////
507     // Data Store API
508 douglas 959
509 douglas 956 /**
510     * Set a user preference.
511     *
512     * @param pref_id preference identifier (0-200)
513     * @param value preferece's value
514     * @error
515     * API_EC_DATA_DATABASE_ERROR
516     * API_EC_PARAM
517     * API_EC_DATA_QUOTA_EXCEEDED
518     * API_EC_DATA_UNKNOWN_ERROR
519     */
520     public function data_setUserPreference($pref_id, $value) {
521     return $this->call_method
522     ('facebook.data.setUserPreference',
523     array('pref_id' => $pref_id,
524     'value' => $value));
525     }
526    
527     /**
528     * Set a user's all preferences for this application.
529     *
530     * @param values preferece values in an associative arrays
531 douglas 959 * @param replace whether to replace all existing preferences or
532 douglas 956 * merge into them.
533     * @error
534     * API_EC_DATA_DATABASE_ERROR
535     * API_EC_PARAM
536     * API_EC_DATA_QUOTA_EXCEEDED
537     * API_EC_DATA_UNKNOWN_ERROR
538     */
539     public function data_setUserPreferences($values, $replace = false) {
540     return $this->call_method
541     ('facebook.data.setUserPreferences',
542     array('values' => json_encode($values),
543     'replace' => $replace));
544     }
545    
546     /**
547     * Get a user preference.
548     *
549     * @param pref_id preference identifier (0-200)
550     * @return preference's value
551     * @error
552     * API_EC_DATA_DATABASE_ERROR
553     * API_EC_PARAM
554     * API_EC_DATA_QUOTA_EXCEEDED
555     * API_EC_DATA_UNKNOWN_ERROR
556     */
557     public function data_getUserPreference($pref_id) {
558     return $this->call_method
559     ('facebook.data.getUserPreference',
560     array('pref_id' => $pref_id));
561     }
562    
563     /**
564     * Get a user preference.
565     *
566     * @return preference values
567     * @error
568     * API_EC_DATA_DATABASE_ERROR
569     * API_EC_DATA_QUOTA_EXCEEDED
570     * API_EC_DATA_UNKNOWN_ERROR
571     */
572     public function data_getUserPreferences() {
573     return $this->call_method
574     ('facebook.data.getUserPreferences',
575     array());
576     }
577    
578     /**
579     * Create a new object type.
580     *
581     * @param name object type's name
582     * @error
583     * API_EC_DATA_DATABASE_ERROR
584     * API_EC_DATA_OBJECT_ALREADY_EXISTS
585     * API_EC_PARAM
586     * API_EC_PERMISSION
587     * API_EC_DATA_INVALID_OPERATION
588     * API_EC_DATA_QUOTA_EXCEEDED
589     * API_EC_DATA_UNKNOWN_ERROR
590     */
591     public function data_createObjectType($name) {
592     return $this->call_method
593     ('facebook.data.createObjectType',
594     array('name' => $name));
595     }
596    
597     /**
598     * Delete an object type.
599     *
600     * @param obj_type object type's name
601     * @error
602     * API_EC_DATA_DATABASE_ERROR
603     * API_EC_DATA_OBJECT_NOT_FOUND
604     * API_EC_PARAM
605     * API_EC_PERMISSION
606     * API_EC_DATA_INVALID_OPERATION
607     * API_EC_DATA_QUOTA_EXCEEDED
608     * API_EC_DATA_UNKNOWN_ERROR
609     */
610     public function data_dropObjectType($obj_type) {
611     return $this->call_method
612     ('facebook.data.dropObjectType',
613     array('obj_type' => $obj_type));
614     }
615    
616     /**
617     * Rename an object type.
618     *
619     * @param obj_type object type's name
620     * @param new_name new object type's name
621     * @error
622     * API_EC_DATA_DATABASE_ERROR
623     * API_EC_DATA_OBJECT_NOT_FOUND
624     * API_EC_DATA_OBJECT_ALREADY_EXISTS
625     * API_EC_PARAM
626     * API_EC_PERMISSION
627     * API_EC_DATA_INVALID_OPERATION
628     * API_EC_DATA_QUOTA_EXCEEDED
629     * API_EC_DATA_UNKNOWN_ERROR
630     */
631     public function data_renameObjectType($obj_type, $new_name) {
632     return $this->call_method
633     ('facebook.data.renameObjectType',
634     array('obj_type' => $obj_type,
635     'new_name' => $new_name));
636     }
637    
638     /**
639     * Add a new property to an object type.
640     *
641     * @param obj_type object type's name
642     * @param prop_name name of the property to add
643     * @param prop_type 1: integer; 2: string; 3: text blob
644     * @error
645     * API_EC_DATA_DATABASE_ERROR
646     * API_EC_DATA_OBJECT_ALREADY_EXISTS
647     * API_EC_PARAM
648     * API_EC_PERMISSION
649     * API_EC_DATA_INVALID_OPERATION
650     * API_EC_DATA_QUOTA_EXCEEDED
651     * API_EC_DATA_UNKNOWN_ERROR
652     */
653 douglas 959 public function data_defineObjectProperty($obj_type, $prop_name, $prop_type) {
654 douglas 956 return $this->call_method
655     ('facebook.data.defineObjectProperty',
656     array('obj_type' => $obj_type,
657     'prop_name' => $prop_name,
658     'prop_type' => $prop_type));
659     }
660    
661     /**
662     * Remove a previously defined property from an object type.
663 douglas 959 *
664 douglas 956 * @param obj_type object type's name
665     * @param prop_name name of the property to remove
666     * @error
667     * API_EC_DATA_DATABASE_ERROR
668     * API_EC_DATA_OBJECT_NOT_FOUND
669     * API_EC_PARAM
670     * API_EC_PERMISSION
671     * API_EC_DATA_INVALID_OPERATION
672     * API_EC_DATA_QUOTA_EXCEEDED
673     * API_EC_DATA_UNKNOWN_ERROR
674     */
675     public function data_undefineObjectProperty($obj_type, $prop_name) {
676     return $this->call_method
677     ('facebook.data.undefineObjectProperty',
678     array('obj_type' => $obj_type,
679     'prop_name' => $prop_name));
680     }
681    
682     /**
683     * Rename a previously defined property of an object type.
684 douglas 959 *
685 douglas 956 * @param obj_type object type's name
686     * @param prop_name name of the property to rename
687     * @param new_name new name to use
688     * @error
689     * API_EC_DATA_DATABASE_ERROR
690     * API_EC_DATA_OBJECT_NOT_FOUND
691     * API_EC_DATA_OBJECT_ALREADY_EXISTS
692     * API_EC_PARAM
693     * API_EC_PERMISSION
694     * API_EC_DATA_INVALID_OPERATION
695     * API_EC_DATA_QUOTA_EXCEEDED
696     * API_EC_DATA_UNKNOWN_ERROR
697     */
698     public function data_renameObjectProperty($obj_type, $prop_name,
699     $new_name) {
700     return $this->call_method
701     ('facebook.data.renameObjectProperty',
702     array('obj_type' => $obj_type,
703     'prop_name' => $prop_name,
704     'new_name' => $new_name));
705     }
706    
707     /**
708     * Retrieve a list of all object types that have defined for the application.
709     *
710     * @return a list of object type names
711     * @error
712     * API_EC_DATA_DATABASE_ERROR
713     * API_EC_PERMISSION
714     * API_EC_DATA_QUOTA_EXCEEDED
715     * API_EC_DATA_UNKNOWN_ERROR
716     */
717     public function data_getObjectTypes() {
718     return $this->call_method
719     ('facebook.data.getObjectTypes',
720     array());
721     }
722    
723     /**
724     * Get definitions of all properties of an object type.
725     *
726     * @param obj_type object type's name
727     * @return pairs of property name and property types
728     * @error
729     * API_EC_DATA_DATABASE_ERROR
730     * API_EC_PARAM
731     * API_EC_PERMISSION
732     * API_EC_DATA_OBJECT_NOT_FOUND
733     * API_EC_DATA_QUOTA_EXCEEDED
734     * API_EC_DATA_UNKNOWN_ERROR
735     */
736     public function data_getObjectType($obj_type) {
737     return $this->call_method
738     ('facebook.data.getObjectType',
739     array('obj_type' => $obj_type));
740     }
741    
742     /**
743     * Create a new object.
744 douglas 959 *
745 douglas 956 * @param obj_type object type's name
746     * @param properties (optional) properties to set initially
747     * @return newly created object's id
748     * @error
749     * API_EC_DATA_DATABASE_ERROR
750     * API_EC_PARAM
751     * API_EC_PERMISSION
752     * API_EC_DATA_INVALID_OPERATION
753     * API_EC_DATA_QUOTA_EXCEEDED
754     * API_EC_DATA_UNKNOWN_ERROR
755     */
756     public function data_createObject($obj_type, $properties = null) {
757     return $this->call_method
758     ('facebook.data.createObject',
759     array('obj_type' => $obj_type,
760     'properties' => json_encode($properties)));
761     }
762    
763     /**
764     * Update an existing object.
765     *
766     * @param obj_id object's id
767     * @param properties new properties
768     * @param replace true for replacing existing properties; false for merging
769     * @error
770     * API_EC_DATA_DATABASE_ERROR
771     * API_EC_DATA_OBJECT_NOT_FOUND
772     * API_EC_PARAM
773     * API_EC_PERMISSION
774     * API_EC_DATA_INVALID_OPERATION
775     * API_EC_DATA_QUOTA_EXCEEDED
776     * API_EC_DATA_UNKNOWN_ERROR
777     */
778     public function data_updateObject($obj_id, $properties, $replace = false) {
779     return $this->call_method
780     ('facebook.data.updateObject',
781     array('obj_id' => $obj_id,
782     'properties' => json_encode($properties),
783     'replace' => $replace));
784     }
785    
786     /**
787     * Delete an existing object.
788     *
789     * @param obj_id object's id
790     * @error
791     * API_EC_DATA_DATABASE_ERROR
792     * API_EC_DATA_OBJECT_NOT_FOUND
793     * API_EC_PARAM
794     * API_EC_PERMISSION
795     * API_EC_DATA_INVALID_OPERATION
796     * API_EC_DATA_QUOTA_EXCEEDED
797     * API_EC_DATA_UNKNOWN_ERROR
798     */
799     public function data_deleteObject($obj_id) {
800     return $this->call_method
801     ('facebook.data.deleteObject',
802     array('obj_id' => $obj_id));
803     }
804    
805     /**
806     * Delete a list of objects.
807     *
808     * @param obj_ids objects to delete
809     * @error
810     * API_EC_DATA_DATABASE_ERROR
811     * API_EC_PARAM
812     * API_EC_PERMISSION
813     * API_EC_DATA_INVALID_OPERATION
814     * API_EC_DATA_QUOTA_EXCEEDED
815     * API_EC_DATA_UNKNOWN_ERROR
816     */
817     public function data_deleteObjects($obj_ids) {
818     return $this->call_method
819     ('facebook.data.deleteObjects',
820     array('obj_ids' => json_encode($obj_ids)));
821     }
822    
823     /**
824     * Get a single property value of an object.
825     *
826     * @param obj_id object's id
827     * @param prop_name individual property's name
828     * @return individual property's value
829     * @error
830     * API_EC_DATA_DATABASE_ERROR
831     * API_EC_DATA_OBJECT_NOT_FOUND
832     * API_EC_PARAM
833     * API_EC_PERMISSION
834     * API_EC_DATA_INVALID_OPERATION
835     * API_EC_DATA_QUOTA_EXCEEDED
836     * API_EC_DATA_UNKNOWN_ERROR
837     */
838     public function data_getObjectProperty($obj_id, $prop_name) {
839     return $this->call_method
840     ('facebook.data.getObjectProperty',
841     array('obj_id' => $obj_id,
842     'prop_name' => $prop_name));
843     }
844    
845     /**
846     * Get properties of an object.
847     *
848     * @param obj_id object's id
849     * @param prop_names (optional) properties to return; null for all.
850     * @return specified properties of an object
851     * @error
852     * API_EC_DATA_DATABASE_ERROR
853     * API_EC_DATA_OBJECT_NOT_FOUND
854     * API_EC_PARAM
855     * API_EC_PERMISSION
856     * API_EC_DATA_INVALID_OPERATION
857     * API_EC_DATA_QUOTA_EXCEEDED
858     * API_EC_DATA_UNKNOWN_ERROR
859     */
860     public function data_getObject($obj_id, $prop_names = null) {
861     return $this->call_method
862     ('facebook.data.getObject',
863     array('obj_id' => $obj_id,
864     'prop_names' => json_encode($prop_names)));
865     }
866    
867     /**
868     * Get properties of a list of objects.
869     *
870     * @param obj_ids object ids
871     * @param prop_names (optional) properties to return; null for all.
872     * @return specified properties of an object
873     * @error
874     * API_EC_DATA_DATABASE_ERROR
875     * API_EC_DATA_OBJECT_NOT_FOUND
876     * API_EC_PARAM
877     * API_EC_PERMISSION
878     * API_EC_DATA_INVALID_OPERATION
879     * API_EC_DATA_QUOTA_EXCEEDED
880     * API_EC_DATA_UNKNOWN_ERROR
881     */
882     public function data_getObjects($obj_ids, $prop_names = null) {
883     return $this->call_method
884     ('facebook.data.getObjects',
885     array('obj_ids' => json_encode($obj_ids),
886     'prop_names' => json_encode($prop_names)));
887     }
888    
889     /**
890     * Set a single property value of an object.
891     *
892     * @param obj_id object's id
893     * @param prop_name individual property's name
894     * @param prop_value new value to set
895     * @error
896     * API_EC_DATA_DATABASE_ERROR
897     * API_EC_DATA_OBJECT_NOT_FOUND
898     * API_EC_PARAM
899     * API_EC_PERMISSION
900     * API_EC_DATA_INVALID_OPERATION
901     * API_EC_DATA_QUOTA_EXCEEDED
902     * API_EC_DATA_UNKNOWN_ERROR
903     */
904     public function data_setObjectProperty($obj_id, $prop_name,
905     $prop_value) {
906     return $this->call_method
907     ('facebook.data.setObjectProperty',
908     array('obj_id' => $obj_id,
909     'prop_name' => $prop_name,
910     'prop_value' => $prop_value));
911     }
912    
913     /**
914     * Read hash value by key.
915 douglas 959 *
916 douglas 956 * @param obj_type object type's name
917     * @param key hash key
918     * @param prop_name (optional) individual property's name
919     * @return hash value
920     * @error
921     * API_EC_DATA_DATABASE_ERROR
922     * API_EC_PARAM
923     * API_EC_PERMISSION
924     * API_EC_DATA_INVALID_OPERATION
925     * API_EC_DATA_QUOTA_EXCEEDED
926     * API_EC_DATA_UNKNOWN_ERROR
927     */
928     public function data_getHashValue($obj_type, $key, $prop_name = null) {
929     return $this->call_method
930     ('facebook.data.getHashValue',
931     array('obj_type' => $obj_type,
932     'key' => $key,
933     'prop_name' => $prop_name));
934     }
935    
936     /**
937     * Write hash value by key.
938 douglas 959 *
939 douglas 956 * @param obj_type object type's name
940     * @param key hash key
941     * @param value hash value
942     * @param prop_name (optional) individual property's name
943     * @error
944     * API_EC_DATA_DATABASE_ERROR
945     * API_EC_PARAM
946     * API_EC_PERMISSION
947     * API_EC_DATA_INVALID_OPERATION
948     * API_EC_DATA_QUOTA_EXCEEDED
949     * API_EC_DATA_UNKNOWN_ERROR
950     */
951     public function data_setHashValue($obj_type, $key, $value, $prop_name = null) {
952     return $this->call_method
953     ('facebook.data.setHashValue',
954     array('obj_type' => $obj_type,
955     'key' => $key,
956     'value' => $value,
957     'prop_name' => $prop_name));
958     }
959    
960     /**
961     * Increase a hash value by specified increment atomically.
962 douglas 959 *
963 douglas 956 * @param obj_type object type's name
964     * @param key hash key
965     * @param prop_name individual property's name
966     * @param increment (optional) default is 1
967     * @return incremented hash value
968     * @error
969     * API_EC_DATA_DATABASE_ERROR
970     * API_EC_PARAM
971     * API_EC_PERMISSION
972     * API_EC_DATA_INVALID_OPERATION
973     * API_EC_DATA_QUOTA_EXCEEDED
974     * API_EC_DATA_UNKNOWN_ERROR
975     */
976     public function data_incHashValue($obj_type, $key, $prop_name, $increment = 1) {
977     return $this->call_method
978     ('facebook.data.incHashValue',
979     array('obj_type' => $obj_type,
980     'key' => $key,
981     'prop_name' => $prop_name,
982     'increment' => $increment));
983     }
984    
985     /**
986     * Remove a hash key and its values.
987     *
988     * @param obj_type object type's name
989     * @param key hash key
990     * @error
991     * API_EC_DATA_DATABASE_ERROR
992     * API_EC_PARAM
993     * API_EC_PERMISSION
994     * API_EC_DATA_INVALID_OPERATION
995     * API_EC_DATA_QUOTA_EXCEEDED
996     * API_EC_DATA_UNKNOWN_ERROR
997     */
998     public function data_removeHashKey($obj_type, $key) {
999     return $this->call_method
1000     ('facebook.data.removeHashKey',
1001     array('obj_type' => $obj_type,
1002     'key' => $key));
1003     }
1004    
1005     /**
1006     * Remove hash keys and their values.
1007     *
1008     * @param obj_type object type's name
1009     * @param keys hash keys
1010     * @error
1011     * API_EC_DATA_DATABASE_ERROR
1012     * API_EC_PARAM
1013     * API_EC_PERMISSION
1014     * API_EC_DATA_INVALID_OPERATION
1015     * API_EC_DATA_QUOTA_EXCEEDED
1016     * API_EC_DATA_UNKNOWN_ERROR
1017     */
1018     public function data_removeHashKeys($obj_type, $keys) {
1019     return $this->call_method
1020     ('facebook.data.removeHashKeys',
1021     array('obj_type' => $obj_type,
1022     'keys' => json_encode($keys)));
1023     }
1024    
1025    
1026     /**
1027     * Define an object association.
1028     *
1029     * @param name name of this association
1030     * @param assoc_type 1: one-way 2: two-way symmetric 3: two-way asymmetric
1031     * @param assoc_info1 needed info about first object type
1032     * @param assoc_info2 needed info about second object type
1033     * @param inverse (optional) name of reverse association
1034     * @error
1035     * API_EC_DATA_DATABASE_ERROR
1036     * API_EC_DATA_OBJECT_ALREADY_EXISTS
1037     * API_EC_PARAM
1038     * API_EC_PERMISSION
1039     * API_EC_DATA_INVALID_OPERATION
1040     * API_EC_DATA_QUOTA_EXCEEDED
1041     * API_EC_DATA_UNKNOWN_ERROR
1042     */
1043     public function data_defineAssociation($name, $assoc_type, $assoc_info1,
1044     $assoc_info2, $inverse = null) {
1045     return $this->call_method
1046     ('facebook.data.defineAssociation',
1047     array('name' => $name,
1048     'assoc_type' => $assoc_type,
1049     'assoc_info1' => json_encode($assoc_info1),
1050     'assoc_info2' => json_encode($assoc_info2),
1051     'inverse' => $inverse));
1052     }
1053 douglas 959
1054 douglas 956 /**
1055     * Undefine an object association.
1056     *
1057     * @param name name of this association
1058     * @error
1059     * API_EC_DATA_DATABASE_ERROR
1060     * API_EC_DATA_OBJECT_NOT_FOUND
1061     * API_EC_PARAM
1062     * API_EC_PERMISSION
1063     * API_EC_DATA_INVALID_OPERATION
1064     * API_EC_DATA_QUOTA_EXCEEDED
1065     * API_EC_DATA_UNKNOWN_ERROR
1066     */
1067     public function data_undefineAssociation($name) {
1068     return $this->call_method
1069     ('facebook.data.undefineAssociation',
1070     array('name' => $name));
1071     }
1072    
1073     /**
1074     * Rename an object association or aliases.
1075     *
1076     * @param name name of this association
1077     * @param new_name (optional) new name of this association
1078     * @param new_alias1 (optional) new alias for object type 1
1079     * @param new_alias2 (optional) new alias for object type 2
1080     * @error
1081     * API_EC_DATA_DATABASE_ERROR
1082     * API_EC_DATA_OBJECT_ALREADY_EXISTS
1083     * API_EC_DATA_OBJECT_NOT_FOUND
1084     * API_EC_PARAM
1085     * API_EC_PERMISSION
1086     * API_EC_DATA_INVALID_OPERATION
1087     * API_EC_DATA_QUOTA_EXCEEDED
1088     * API_EC_DATA_UNKNOWN_ERROR
1089     */
1090     public function data_renameAssociation($name, $new_name, $new_alias1 = null,
1091     $new_alias2 = null) {
1092     return $this->call_method
1093     ('facebook.data.renameAssociation',
1094     array('name' => $name,
1095     'new_name' => $new_name,
1096     'new_alias1' => $new_alias1,
1097     'new_alias2' => $new_alias2));
1098     }
1099 douglas 959
1100 douglas 956 /**
1101     * Get definition of an object association.
1102     *
1103     * @param name name of this association
1104     * @return specified association
1105     * @error
1106     * API_EC_DATA_DATABASE_ERROR
1107     * API_EC_DATA_OBJECT_NOT_FOUND
1108     * API_EC_PARAM
1109     * API_EC_PERMISSION
1110     * API_EC_DATA_QUOTA_EXCEEDED
1111     * API_EC_DATA_UNKNOWN_ERROR
1112     */
1113     public function data_getAssociationDefinition($name) {
1114     return $this->call_method
1115     ('facebook.data.getAssociationDefinition',
1116     array('name' => $name));
1117     }
1118 douglas 959
1119 douglas 956 /**
1120     * Get definition of all associations.
1121     *
1122     * @return all defined associations
1123     * @error
1124     * API_EC_DATA_DATABASE_ERROR
1125     * API_EC_PERMISSION
1126     * API_EC_DATA_QUOTA_EXCEEDED
1127     * API_EC_DATA_UNKNOWN_ERROR
1128     */
1129     public function data_getAssociationDefinitions() {
1130     return $this->call_method
1131     ('facebook.data.getAssociationDefinitions',
1132     array());
1133     }
1134    
1135     /**
1136     * Create or modify an association between two objects.
1137 douglas 959 *
1138 douglas 956 * @param name name of association
1139     * @param obj_id1 id of first object
1140     * @param obj_id2 id of second object
1141     * @param data (optional) extra string data to store
1142     * @param assoc_time (optional) extra time data; default to creation time
1143     * @error
1144     * API_EC_DATA_DATABASE_ERROR
1145     * API_EC_PARAM
1146     * API_EC_PERMISSION
1147     * API_EC_DATA_INVALID_OPERATION
1148     * API_EC_DATA_QUOTA_EXCEEDED
1149     * API_EC_DATA_UNKNOWN_ERROR
1150     */
1151     public function data_setAssociation($name, $obj_id1, $obj_id2, $data = null,
1152     $assoc_time = null) {
1153     return $this->call_method
1154     ('facebook.data.setAssociation',
1155     array('name' => $name,
1156     'obj_id1' => $obj_id1,
1157     'obj_id2' => $obj_id2,
1158     'data' => $data,
1159     'assoc_time' => $assoc_time));
1160     }
1161    
1162     /**
1163     * Create or modify associations between objects.
1164 douglas 959 *
1165 douglas 956 * @param assocs associations to set
1166     * @param name (optional) name of association
1167     * @error
1168     * API_EC_DATA_DATABASE_ERROR
1169     * API_EC_PARAM
1170     * API_EC_PERMISSION
1171     * API_EC_DATA_INVALID_OPERATION
1172     * API_EC_DATA_QUOTA_EXCEEDED
1173     * API_EC_DATA_UNKNOWN_ERROR
1174     */
1175     public function data_setAssociations($assocs, $name = null) {
1176     return $this->call_method
1177     ('facebook.data.setAssociations',
1178     array('assocs' => json_encode($assocs),
1179     'name' => $name));
1180     }
1181    
1182     /**
1183     * Remove an association between two objects.
1184 douglas 959 *
1185 douglas 956 * @param name name of association
1186     * @param obj_id1 id of first object
1187     * @param obj_id2 id of second object
1188     * @error
1189     * API_EC_DATA_DATABASE_ERROR
1190     * API_EC_DATA_OBJECT_NOT_FOUND
1191     * API_EC_PARAM
1192     * API_EC_PERMISSION
1193     * API_EC_DATA_QUOTA_EXCEEDED
1194     * API_EC_DATA_UNKNOWN_ERROR
1195     */
1196     public function data_removeAssociation($name, $obj_id1, $obj_id2) {
1197     return $this->call_method
1198     ('facebook.data.removeAssociation',
1199 douglas 959 array('name' => $name,
1200     'obj_id1' => $obj_id1,
1201 douglas 956 'obj_id2' => $obj_id2));
1202     }
1203    
1204     /**
1205     * Remove associations between objects by specifying pairs of object ids.
1206 douglas 959 *
1207 douglas 956 * @param assocs associations to remove
1208     * @param name (optional) name of association
1209     * @error
1210     * API_EC_DATA_DATABASE_ERROR
1211     * API_EC_DATA_OBJECT_NOT_FOUND
1212     * API_EC_PARAM
1213     * API_EC_PERMISSION
1214     * API_EC_DATA_QUOTA_EXCEEDED
1215     * API_EC_DATA_UNKNOWN_ERROR
1216     */
1217     public function data_removeAssociations($assocs, $name = null) {
1218     return $this->call_method
1219     ('facebook.data.removeAssociations',
1220     array('assocs' => json_encode($assocs),
1221     'name' => $name));
1222     }
1223    
1224     /**
1225     * Remove associations between objects by specifying one object id.
1226 douglas 959 *
1227 douglas 956 * @param name name of association
1228     * @param obj_id who's association to remove
1229     * @error
1230     * API_EC_DATA_DATABASE_ERROR
1231     * API_EC_DATA_OBJECT_NOT_FOUND
1232     * API_EC_PARAM
1233     * API_EC_PERMISSION
1234     * API_EC_DATA_INVALID_OPERATION
1235     * API_EC_DATA_QUOTA_EXCEEDED
1236     * API_EC_DATA_UNKNOWN_ERROR
1237     */
1238     public function data_removeAssociatedObjects($name, $obj_id) {
1239     return $this->call_method
1240     ('facebook.data.removeAssociatedObjects',
1241     array('name' => $name,
1242     'obj_id' => $obj_id));
1243     }
1244    
1245     /**
1246     * Retrieve a list of associated objects.
1247     *
1248     * @param name name of association
1249     * @param obj_id who's association to retrieve
1250     * @param no_data only return object ids
1251     * @return associated objects
1252     * @error
1253     * API_EC_DATA_DATABASE_ERROR
1254     * API_EC_DATA_OBJECT_NOT_FOUND
1255     * API_EC_PARAM
1256     * API_EC_PERMISSION
1257     * API_EC_DATA_INVALID_OPERATION
1258     * API_EC_DATA_QUOTA_EXCEEDED
1259     * API_EC_DATA_UNKNOWN_ERROR
1260     */
1261     public function data_getAssociatedObjects($name, $obj_id, $no_data = true) {
1262     return $this->call_method
1263     ('facebook.data.getAssociatedObjects',
1264 douglas 959 array('name' => $name,
1265     'obj_id' => $obj_id,
1266 douglas 956 'no_data' => $no_data));
1267     }
1268    
1269     /**
1270     * Count associated objects.
1271     *
1272     * @param name name of association
1273     * @param obj_id who's association to retrieve
1274     * @return associated object's count
1275     * @error
1276     * API_EC_DATA_DATABASE_ERROR
1277     * API_EC_DATA_OBJECT_NOT_FOUND
1278     * API_EC_PARAM
1279     * API_EC_PERMISSION
1280     * API_EC_DATA_INVALID_OPERATION
1281     * API_EC_DATA_QUOTA_EXCEEDED
1282     * API_EC_DATA_UNKNOWN_ERROR
1283     */
1284     public function data_getAssociatedObjectCount($name, $obj_id) {
1285     return $this->call_method
1286     ('facebook.data.getAssociatedObjectCount',
1287     array('name' => $name,
1288     'obj_id' => $obj_id));
1289     }
1290    
1291     /**
1292     * Get a list of associated object counts.
1293     *
1294     * @param name name of association
1295     * @param obj_ids whose association to retrieve
1296     * @return associated object counts
1297     * @error
1298     * API_EC_DATA_DATABASE_ERROR
1299     * API_EC_DATA_OBJECT_NOT_FOUND
1300     * API_EC_PARAM
1301     * API_EC_PERMISSION
1302     * API_EC_DATA_INVALID_OPERATION
1303     * API_EC_DATA_QUOTA_EXCEEDED
1304     * API_EC_DATA_UNKNOWN_ERROR
1305     */
1306     public function data_getAssociatedObjectCounts($name, $obj_ids) {
1307     return $this->call_method
1308     ('facebook.data.getAssociatedObjectCounts',
1309     array('name' => $name,
1310     'obj_ids' => json_encode($obj_ids)));
1311     }
1312    
1313     /**
1314     * Find all associations between two objects.
1315     *
1316     * @param obj_id1 id of first object
1317     * @param obj_id2 id of second object
1318     * @param no_data only return association names without data
1319     * @return all associations between objects
1320     * @error
1321     * API_EC_DATA_DATABASE_ERROR
1322     * API_EC_PARAM
1323     * API_EC_PERMISSION
1324     * API_EC_DATA_QUOTA_EXCEEDED
1325     * API_EC_DATA_UNKNOWN_ERROR
1326     */
1327     public function data_getAssociations($obj_id1, $obj_id2, $no_data = true) {
1328     return $this->call_method
1329     ('facebook.data.getAssociations',
1330     array('obj_id1' => $obj_id1,
1331     'obj_id2' => $obj_id2,
1332     'no_data' => $no_data));
1333     }
1334    
1335 douglas 943 /* UTILITY FUNCTIONS */
1336    
1337     public function call_method($method, $params) {
1338 douglas 946 if ($this->json) {
1339     $json = $this->post_request($method, $params);
1340     # XXX: silly facebook with its invalid JSON
1341     $valid = preg_match('/^[\[{].*[\]}]$/', $json);
1342     $array = json_decode($valid ? $json : "[$json]", true);
1343     $result = $valid ? $array : $array[0];
1344     } else {
1345     $xml = $this->post_request($method, $params);
1346     $sxml = simplexml_load_string($xml);
1347     $result = self::convert_simplexml_to_array($sxml);
1348     if ($GLOBALS['facebook_config']['debug']) {
1349     // output the raw xml and its corresponding php object, for debugging:
1350     print '<div style="margin: 10px 30px; padding: 5px; border: 2px solid black; background: gray; color: white; font-size: 12px; font-weight: bold;">';
1351     $this->cur_id++;
1352     print $this->cur_id . ': Called ' . $method . ', show ' .
1353     '<a href=# onclick="return toggleDisplay(' . $this->cur_id . ', \'params\');">Params</a> | '.
1354     '<a href=# onclick="return toggleDisplay(' . $this->cur_id . ', \'xml\');">XML</a> | '.
1355     '<a href=# onclick="return toggleDisplay(' . $this->cur_id . ', \'sxml\');">SXML</a> | '.
1356     '<a href=# onclick="return toggleDisplay(' . $this->cur_id . ', \'php\');">PHP</a>';
1357     print '<pre id="params'.$this->cur_id.'" style="display: none; overflow: auto;">'.print_r($params, true).'</pre>';
1358     print '<pre id="xml'.$this->cur_id.'" style="display: none; overflow: auto;">'.htmlspecialchars($xml).'</pre>';
1359     print '<pre id="php'.$this->cur_id.'" style="display: none; overflow: auto;">'.print_r($result, true).'</pre>';
1360     print '<pre id="sxml'.$this->cur_id.'" style="display: none; overflow: auto;">'.print_r($sxml, true).'</pre>';
1361     print '</div>';
1362     }
1363 douglas 943 }
1364     if (is_array($result) && isset($result['error_code'])) {
1365     throw new FacebookRestClientException($result['error_msg'], $result['error_code']);
1366     }
1367     return $result;
1368     }
1369    
1370     public function post_request($method, $params) {
1371     $params['method'] = $method;
1372     $params['session_key'] = $this->session_key;
1373     $params['api_key'] = $this->api_key;
1374     $params['call_id'] = microtime(true);
1375     if ($params['call_id'] <= $this->last_call_id) {
1376     $params['call_id'] = $this->last_call_id + 0.001;
1377     }
1378     $this->last_call_id = $params['call_id'];
1379     if (!isset($params['v'])) {
1380     $params['v'] = '1.0';
1381     }
1382 douglas 946 if ($this->json)
1383     $params['format'] = 'JSON';
1384 douglas 943 $post_params = array();
1385     foreach ($params as $key => &$val) {
1386     if (is_array($val)) $val = implode(',', $val);
1387     $post_params[] = $key.'='.urlencode($val);
1388     }
1389 douglas 946 $post_params[] = 'sig='.Facebook::generate_sig($params, $this->secret);
1390 douglas 943 $post_string = implode('&', $post_params);
1391    
1392 douglas 946 if ($this->json) {
1393     $result = file_get_contents($this->server_addr, false, stream_context_create(
1394     array('http' =>
1395     array('method' => 'POST',
1396     'header' => 'Content-type: application/x-www-form-urlencoded'."\r\n".
1397     'User-Agent: Facebook API PHP5 Client 1.1 (non-curl) '.phpversion()."\r\n".
1398     'Content-length: ' . strlen($post_string),
1399     'content' => $post_string))));
1400     } elseif (function_exists('curl_init')) {
1401 douglas 943 // Use CURL if installed...
1402     $ch = curl_init();
1403     curl_setopt($ch, CURLOPT_URL, $this->server_addr);
1404     curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string);
1405     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
1406     curl_setopt($ch, CURLOPT_USERAGENT, 'Facebook API PHP5 Client 1.1 (curl) ' . phpversion());
1407     $result = curl_exec($ch);
1408     curl_close($ch);
1409     } else {
1410     // Non-CURL based version...
1411     $context =
1412     array('http' =>
1413     array('method' => 'POST',
1414     'header' => 'Content-type: application/x-www-form-urlencoded'."\r\n".
1415     'User-Agent: Facebook API PHP5 Client 1.1 (non-curl) '.phpversion()."\r\n".
1416     'Content-length: ' . strlen($post_string),
1417     'content' => $post_string));
1418     $contextid=stream_context_create($context);
1419     $sock=fopen($this->server_addr, 'r', false, $contextid);
1420     if ($sock) {
1421     $result='';
1422     while (!feof($sock))
1423     $result.=fgets($sock, 4096);
1424    
1425     fclose($sock);
1426     }
1427     }
1428     return $result;
1429     }
1430    
1431     public static function convert_simplexml_to_array($sxml) {
1432     $arr = array();
1433     if ($sxml) {
1434     foreach ($sxml as $k => $v) {
1435     if ($sxml['list']) {
1436     $arr[] = self::convert_simplexml_to_array($v);
1437     } else {
1438     $arr[$k] = self::convert_simplexml_to_array($v);
1439     }
1440     }
1441     }
1442     if (sizeof($arr) > 0) {
1443     return $arr;
1444     } else {
1445     return (string)$sxml;
1446 douglas 959 }
1447 douglas 943 }
1448     }
1449    
1450     class FacebookRestClientException extends Exception {
1451     }
1452    
1453     // Supporting methods and values------
1454    
1455     /**
1456     * Error codes and descriptions for the Facebook API.
1457     */
1458    
1459     class FacebookAPIErrorCodes {
1460    
1461     const API_EC_SUCCESS = 0;
1462    
1463     /*
1464     * GENERAL ERRORS
1465     */
1466     const API_EC_UNKNOWN = 1;
1467     const API_EC_SERVICE = 2;
1468     const API_EC_METHOD = 3;
1469     const API_EC_TOO_MANY_CALLS = 4;
1470     const API_EC_BAD_IP = 5;
1471    
1472     /*
1473     * PARAMETER ERRORS
1474     */
1475     const API_EC_PARAM = 100;
1476     const API_EC_PARAM_API_KEY = 101;
1477     const API_EC_PARAM_SESSION_KEY = 102;
1478     const API_EC_PARAM_CALL_ID = 103;
1479     const API_EC_PARAM_SIGNATURE = 104;
1480     const API_EC_PARAM_USER_ID = 110;
1481     const API_EC_PARAM_USER_FIELD = 111;
1482     const API_EC_PARAM_SOCIAL_FIELD = 112;
1483     const API_EC_PARAM_ALBUM_ID = 120;
1484    
1485     /*
1486     * USER PERMISSIONS ERRORS
1487     */
1488     const API_EC_PERMISSION = 200;
1489     const API_EC_PERMISSION_USER = 210;
1490     const API_EC_PERMISSION_ALBUM = 220;
1491     const API_EC_PERMISSION_PHOTO = 221;
1492    
1493     const FQL_EC_PARSER = 601;
1494     const FQL_EC_UNKNOWN_FIELD = 602;
1495     const FQL_EC_UNKNOWN_TABLE = 603;
1496     const FQL_EC_NOT_INDEXABLE = 604;
1497 douglas 956
1498     /**
1499     * DATA STORE API ERRORS
1500     */
1501     const API_EC_DATA_UNKNOWN_ERROR = 800;
1502     const API_EC_DATA_INVALID_OPERATION = 801;
1503     const API_EC_DATA_QUOTA_EXCEEDED = 802;
1504     const API_EC_DATA_OBJECT_NOT_FOUND = 803;
1505     const API_EC_DATA_OBJECT_ALREADY_EXISTS = 804;
1506     const API_EC_DATA_DATABASE_ERROR = 805;
1507 douglas 959
1508 douglas 943 public static $api_error_descriptions = array(
1509     API_EC_SUCCESS => 'Success',
1510     API_EC_UNKNOWN => 'An unknown error occurred',
1511     API_EC_SERVICE => 'Service temporarily unavailable',
1512     API_EC_METHOD => 'Unknown method',
1513     API_EC_TOO_MANY_CALLS => 'Application request limit reached',
1514     API_EC_BAD_IP => 'Unauthorized source IP address',
1515     API_EC_PARAM => 'Invalid parameter',
1516     API_EC_PARAM_API_KEY => 'Invalid API key',
1517     API_EC_PARAM_SESSION_KEY => 'Session key invalid or no longer valid',
1518     API_EC_PARAM_CALL_ID => 'Call_id must be greater than previous',
1519     API_EC_PARAM_SIGNATURE => 'Incorrect signature',
1520     API_EC_PARAM_USER_ID => 'Invalid user id',
1521     API_EC_PARAM_USER_FIELD => 'Invalid user info field',
1522     API_EC_PARAM_SOCIAL_FIELD => 'Invalid user field',
1523     API_EC_PARAM_ALBUM_ID => 'Invalid album id',
1524     API_EC_PERMISSION => 'Permissions error',
1525     API_EC_PERMISSION_USER => 'User not visible',
1526     API_EC_PERMISSION_ALBUM => 'Album not visible',
1527     API_EC_PERMISSION_PHOTO => 'Photo not visible',
1528     FQL_EC_PARSER => 'FQL: Parser Error',
1529     FQL_EC_UNKNOWN_FIELD => 'FQL: Unknown Field',
1530     FQL_EC_UNKNOWN_TABLE => 'FQL: Unknown Table',
1531     FQL_EC_NOT_INDEXABLE => 'FQL: Statement not indexable',
1532     FQL_EC_UNKNOWN_FUNCTION => 'FQL: Attempted to call unknown function',
1533     FQL_EC_INVALID_PARAM => 'FQL: Invalid parameter passed in',
1534 douglas 956 API_EC_DATA_UNKNOWN_ERROR => 'Unknown data store API error',
1535     API_EC_DATA_INVALID_OPERATION => 'Invalid operation',
1536     API_EC_DATA_QUOTA_EXCEEDED => 'Data store allowable quota was exceeded',
1537     API_EC_DATA_OBJECT_NOT_FOUND => 'Specified object cannot be found',
1538     API_EC_DATA_OBJECT_ALREADY_EXISTS => 'Specified object already exists',
1539     API_EC_DATA_DATABASE_ERROR => 'A database error occurred. Please try again',
1540 douglas 943 );
1541     }
1542    
1543     $profile_field_array = array(
1544     "about_me",
1545     "activities",
1546     "affiliations",
1547     "birthday",
1548     "books",
1549     "current_location",
1550     "education_history",
1551     "first_name",
1552     "hometown_location",
1553     "hs_info",
1554     "interests",
1555     "is_app_user",
1556     "last_name",
1557     "meeting_for",
1558     "meeting_sex",
1559     "movies",
1560     "music",
1561     "name",
1562     "notes_count",
1563     "pic",
1564     "pic_big",
1565     "pic_small",
1566     "political",
1567     "profile_update_time",
1568     "quotes",
1569     "relationship_status",
1570     "religion",
1571 douglas 959 "sex",
1572 douglas 943 "significant_other_id",
1573     "status",
1574     "timezone",
1575     "tv",
1576 douglas 959 "wall_count",
1577 douglas 943 "work_history");
1578     ?>

Properties

Name Value
svn:keywords Id