ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/facebook/trunk/facebookapi_php5_restlib.php
Revision: 956
Committed: 2007-10-11T02:45:01-07:00 (17 years, 8 months ago) by douglas
File size: 53975 byte(s)
Log Message:
Merged with 2007-10-10!

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     * @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     * 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     * @param string $auth_token the token returned by auth_createToken or
85     * 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     * @param int $uid Optional: User associated with events.
101     * 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     * @param int $start_time Optional: Filter with this UTC as lower bound.
105     * A null or zero parameter indicates no lower bound.
106     * @param int $end_time Optional: Filter with this UTC as upper bound.
107     * 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     'start_time' => $start_time,
120     '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     public function feed_publishStoryToUser($title, $body,
148     $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    
165     public function feed_publishActionOfUser($title, $body,
166     $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     * 1 => array('uid1' => id_2, 'uid2' => id_B, 'are_friends' => 0)
216     * ...)
217     */
218     public function friends_areFriends($uids1, $uids2) {
219     return $this->call_method('facebook.friends.areFriends',
220     array('uids1'=>$uids1, 'uids2'=>$uids2));
221     }
222    
223     /**
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    
234     /**
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     * @param int $uid Optional: User associated with groups.
246     * 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     * @return assoc array of four membership lists, with keys
262     * '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     * @return assoc array of
272     * notification count objects for 'messages', 'pokes' and 'shares',
273     * 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     * Sends a request to the specified user (e.g. "you have 1 event invitation")
291     * @param array $to_ids user ids to receive the request (must be friends with sender, capped at 10)
292     * @param string $type type of request, e.g. "event" (as in "You have an event invitation.")
293     * @param string $content fbml content of the request. really stripped down fbml - just
294     * text/names/links. also, use the special tag <fb:req-choice url="" label="" />
295     * to specify the buttons to be included.
296     * @param string $image url of an image to show beside the request
297     * @param bool $invite whether to call it an "invitation" or a "request"
298     * @return string url which you should send the logged in user to to finalize the message.
299     */
300     public function notifications_sendRequest($to_ids, $type, $content, $image, $invite) {
301     return $this->call_method('facebook.notifications.sendRequest',
302     array('to_ids' => $to_ids, 'type' => $type, 'content' => $content,
303     'image' => $image, 'invite' => $invite));
304     }
305    
306     /**
307     * Returns photos according to the filters specified.
308     * @param int $subj_id Optional: Filter by uid of user tagged in the photos.
309     * @param int $aid Optional: Filter by an album, as returned by
310     * photos_getAlbums.
311     * @param array $pids Optional: Restrict to a list of pids
312     * Note that at least one of these parameters needs to be specified, or an
313     * error is returned.
314     * @return array of photo objects.
315     */
316     public function photos_get($subj_id, $aid, $pids) {
317     return $this->call_method('facebook.photos.get',
318     array('subj_id' => $subj_id, 'aid' => $aid, 'pids' => $pids));
319     }
320    
321     /**
322     * Returns the albums created by the given user.
323     * @param int $uid Optional: the uid of the user whose albums you want.
324     * A null value will return the albums of the session user.
325     * @param array $aids Optional: a list of aids to restrict the query.
326     * Note that at least one of the (uid, aids) parameters must be specified.
327     * @returns an array of album objects.
328     */
329     public function photos_getAlbums($uid, $aids) {
330     return $this->call_method('facebook.photos.getAlbums',
331     array('uid' => $uid,
332     'aids' => $aids));
333     }
334    
335     /**
336     * Returns the tags on all photos specified.
337     * @param string $pids : a list of pids to query
338     * @return array of photo tag objects, with include pid, subject uid,
339     * and two floating-point numbers (xcoord, ycoord) for tag pixel location
340     */
341     public function photos_getTags($pids) {
342     return $this->call_method('facebook.photos.getTags',
343     array('pids' => $pids));
344     }
345    
346     /**
347     * Returns the requested info fields for the requested set of users
348     * @param array $uids an array of user ids
349     * @param array $fields an array of strings describing the info fields desired
350     * @return array of users
351     */
352     public function users_getInfo($uids, $fields) {
353     return $this->call_method('facebook.users.getInfo', array('uids' => $uids, 'fields' => $fields));
354     }
355    
356     /**
357     * Returns the user corresponding to the current session object.
358     * @return integer uid
359     */
360     public function users_getLoggedInUser(){
361     return $this->call_method('facebook.users.getLoggedInUser', array());
362     }
363    
364    
365     /**
366     * Returns whether or not the user corresponding to the current session object has the app installed
367     * @return boolean
368     */
369     public function users_isAppAdded() {
370     if (isset($this->added)) {
371     return $this->added;
372     }
373     return $this->call_method('facebook.users.isAppAdded', array());
374     }
375    
376     /**
377     * Sets the FBML for the profile of the user attached to this session
378     * @param string $markup The FBML that describes the profile presence of this app for the user
379     * @return array A list of strings describing any compile errors for the submitted FBML
380     */
381     public function profile_setFBML($markup, $uid = null) {
382     return $this->call_method('facebook.profile.setFBML', array('markup' => $markup, 'uid' => $uid));
383     }
384    
385     public function profile_getFBML($uid) {
386     return $this->call_method('facebook.profile.getFBML', array('uid' => $uid));
387     }
388    
389     public function fbml_refreshImgSrc($url) {
390     return $this->call_method('facebook.fbml.refreshImgSrc', array('url' => $url));
391     }
392    
393     public function fbml_refreshRefUrl($url) {
394     return $this->call_method('facebook.fbml.refreshRefUrl', array('url' => $url));
395     }
396    
397     public function fbml_setRefHandle($handle, $fbml) {
398     return $this->call_method('facebook.fbml.setRefHandle', array('handle' => $handle, 'fbml' => $fbml));
399     }
400    
401 douglas 956 /**
402     * Get all the marketplace categories
403     *
404     * @return array A list of category names
405     */
406     function marketplace_getCategories() {
407     return $this->call_method('facebook.marketplace.getCategories', array());
408     }
409    
410     /**
411     * Get all the marketplace subcategories for a particular category
412     *
413     * @param category The category for which we are pulling subcategories
414     * @return array A list of subcategory names
415     */
416     function marketplace_getSubCategories($category) {
417     return $this->call_method('facebook.marketplace.getSubCategories', array('category' => $category));
418     }
419    
420     /**
421     * Get listings by either listing_id or user
422     *
423     * @param listing_ids An array of listing_ids (optional)
424     * @param uids An array of user ids (optional)
425     * @return array The data for matched listings
426     */
427     function marketplace_getListings($listing_ids, $uids) {
428     return $this->call_method('facebook.marketplace.getListings', array('listing_ids' => $listing_ids, 'uids' => $uids));
429     }
430    
431     /**
432     * Search for Marketplace listings. All arguments are optional, though at least
433     * one must be filled out to retrieve results.
434     *
435     * @param category The category in which to search (optional)
436     * @param subcategory The subcategory in which to search (optional)
437     * @param query A query string (optional)
438     * @return array The data for matched listings
439     */
440     function marketplace_search($category, $subcategory, $query) {
441     return $this->call_method('facebook.marketplace.search', array('category' => $category, 'subcategory' => $subcategory, 'query' => $query));
442     }
443    
444     /**
445     * Remove a listing from Marketplace
446     *
447     * @param listing_id The id of the listing to be removed
448     * @param status 'SUCCESS', 'NOT_SUCCESS', or 'DEFAULT'
449     * @return bool True on success
450     */
451     function marketplace_removeListing($listing_id, $status='DEFAULT') {
452     return $this->call_method('facebook.marketplace.removeListing',
453     array('listing_id'=>$listing_id,
454     'status'=>$status));
455     }
456    
457     /**
458     * Create/modify a Marketplace listing for the loggedinuser
459     *
460     * @param int listing_id The id of a listing to be modified, 0 for a new listing.
461     * @param show_on_profile bool Should we show this listing on the user's profile
462     * @param attrs array An array of the listing data
463     * @return int The listing_id (unchanged if modifying an existing listing)
464     */
465     function marketplace_createListing($listing_id, $show_on_profile, $attrs) {
466     return $this->call_method('facebook.marketplace.createListing',
467     array('listing_id'=>$listing_id,
468     'show_on_profile'=>$show_on_profile,
469     'attrs'=>json_encode($attrs)));
470     }
471    
472    
473     /////////////////////////////////////////////////////////////////////////////
474     // Data Store API
475    
476     /**
477     * Set a user preference.
478     *
479     * @param pref_id preference identifier (0-200)
480     * @param value preferece's value
481     * @error
482     * API_EC_DATA_DATABASE_ERROR
483     * API_EC_PARAM
484     * API_EC_DATA_QUOTA_EXCEEDED
485     * API_EC_DATA_UNKNOWN_ERROR
486     */
487     public function data_setUserPreference($pref_id, $value) {
488     return $this->call_method
489     ('facebook.data.setUserPreference',
490     array('pref_id' => $pref_id,
491     'value' => $value));
492     }
493    
494     /**
495     * Set a user's all preferences for this application.
496     *
497     * @param values preferece values in an associative arrays
498     * @param replace whether to replace all existing preferences or
499     * merge into them.
500     * @error
501     * API_EC_DATA_DATABASE_ERROR
502     * API_EC_PARAM
503     * API_EC_DATA_QUOTA_EXCEEDED
504     * API_EC_DATA_UNKNOWN_ERROR
505     */
506     public function data_setUserPreferences($values, $replace = false) {
507     return $this->call_method
508     ('facebook.data.setUserPreferences',
509     array('values' => json_encode($values),
510     'replace' => $replace));
511     }
512    
513     /**
514     * Get a user preference.
515     *
516     * @param pref_id preference identifier (0-200)
517     * @return preference's value
518     * @error
519     * API_EC_DATA_DATABASE_ERROR
520     * API_EC_PARAM
521     * API_EC_DATA_QUOTA_EXCEEDED
522     * API_EC_DATA_UNKNOWN_ERROR
523     */
524     public function data_getUserPreference($pref_id) {
525     return $this->call_method
526     ('facebook.data.getUserPreference',
527     array('pref_id' => $pref_id));
528     }
529    
530     /**
531     * Get a user preference.
532     *
533     * @return preference values
534     * @error
535     * API_EC_DATA_DATABASE_ERROR
536     * API_EC_DATA_QUOTA_EXCEEDED
537     * API_EC_DATA_UNKNOWN_ERROR
538     */
539     public function data_getUserPreferences() {
540     return $this->call_method
541     ('facebook.data.getUserPreferences',
542     array());
543     }
544    
545     /**
546     * Create a new object type.
547     *
548     * @param name object type's name
549     * @error
550     * API_EC_DATA_DATABASE_ERROR
551     * API_EC_DATA_OBJECT_ALREADY_EXISTS
552     * API_EC_PARAM
553     * API_EC_PERMISSION
554     * API_EC_DATA_INVALID_OPERATION
555     * API_EC_DATA_QUOTA_EXCEEDED
556     * API_EC_DATA_UNKNOWN_ERROR
557     */
558     public function data_createObjectType($name) {
559     return $this->call_method
560     ('facebook.data.createObjectType',
561     array('name' => $name));
562     }
563    
564     /**
565     * Delete an object type.
566     *
567     * @param obj_type object type's name
568     * @error
569     * API_EC_DATA_DATABASE_ERROR
570     * API_EC_DATA_OBJECT_NOT_FOUND
571     * API_EC_PARAM
572     * API_EC_PERMISSION
573     * API_EC_DATA_INVALID_OPERATION
574     * API_EC_DATA_QUOTA_EXCEEDED
575     * API_EC_DATA_UNKNOWN_ERROR
576     */
577     public function data_dropObjectType($obj_type) {
578     return $this->call_method
579     ('facebook.data.dropObjectType',
580     array('obj_type' => $obj_type));
581     }
582    
583     /**
584     * Rename an object type.
585     *
586     * @param obj_type object type's name
587     * @param new_name new object type's name
588     * @error
589     * API_EC_DATA_DATABASE_ERROR
590     * API_EC_DATA_OBJECT_NOT_FOUND
591     * API_EC_DATA_OBJECT_ALREADY_EXISTS
592     * API_EC_PARAM
593     * API_EC_PERMISSION
594     * API_EC_DATA_INVALID_OPERATION
595     * API_EC_DATA_QUOTA_EXCEEDED
596     * API_EC_DATA_UNKNOWN_ERROR
597     */
598     public function data_renameObjectType($obj_type, $new_name) {
599     return $this->call_method
600     ('facebook.data.renameObjectType',
601     array('obj_type' => $obj_type,
602     'new_name' => $new_name));
603     }
604    
605     /**
606     * Add a new property to an object type.
607     *
608     * @param obj_type object type's name
609     * @param prop_name name of the property to add
610     * @param prop_type 1: integer; 2: string; 3: text blob
611     * @error
612     * API_EC_DATA_DATABASE_ERROR
613     * API_EC_DATA_OBJECT_ALREADY_EXISTS
614     * API_EC_PARAM
615     * API_EC_PERMISSION
616     * API_EC_DATA_INVALID_OPERATION
617     * API_EC_DATA_QUOTA_EXCEEDED
618     * API_EC_DATA_UNKNOWN_ERROR
619     */
620     public function data_defineObjectProperty($obj_type, $prop_name, $prop_type){
621     return $this->call_method
622     ('facebook.data.defineObjectProperty',
623     array('obj_type' => $obj_type,
624     'prop_name' => $prop_name,
625     'prop_type' => $prop_type));
626     }
627    
628     /**
629     * Remove a previously defined property from an object type.
630     *
631     * @param obj_type object type's name
632     * @param prop_name name of the property to remove
633     * @error
634     * API_EC_DATA_DATABASE_ERROR
635     * API_EC_DATA_OBJECT_NOT_FOUND
636     * API_EC_PARAM
637     * API_EC_PERMISSION
638     * API_EC_DATA_INVALID_OPERATION
639     * API_EC_DATA_QUOTA_EXCEEDED
640     * API_EC_DATA_UNKNOWN_ERROR
641     */
642     public function data_undefineObjectProperty($obj_type, $prop_name) {
643     return $this->call_method
644     ('facebook.data.undefineObjectProperty',
645     array('obj_type' => $obj_type,
646     'prop_name' => $prop_name));
647     }
648    
649     /**
650     * Rename a previously defined property of an object type.
651     *
652     * @param obj_type object type's name
653     * @param prop_name name of the property to rename
654     * @param new_name new name to use
655     * @error
656     * API_EC_DATA_DATABASE_ERROR
657     * API_EC_DATA_OBJECT_NOT_FOUND
658     * API_EC_DATA_OBJECT_ALREADY_EXISTS
659     * API_EC_PARAM
660     * API_EC_PERMISSION
661     * API_EC_DATA_INVALID_OPERATION
662     * API_EC_DATA_QUOTA_EXCEEDED
663     * API_EC_DATA_UNKNOWN_ERROR
664     */
665     public function data_renameObjectProperty($obj_type, $prop_name,
666     $new_name) {
667     return $this->call_method
668     ('facebook.data.renameObjectProperty',
669     array('obj_type' => $obj_type,
670     'prop_name' => $prop_name,
671     'new_name' => $new_name));
672     }
673    
674     /**
675     * Retrieve a list of all object types that have defined for the application.
676     *
677     * @return a list of object type names
678     * @error
679     * API_EC_DATA_DATABASE_ERROR
680     * API_EC_PERMISSION
681     * API_EC_DATA_QUOTA_EXCEEDED
682     * API_EC_DATA_UNKNOWN_ERROR
683     */
684     public function data_getObjectTypes() {
685     return $this->call_method
686     ('facebook.data.getObjectTypes',
687     array());
688     }
689    
690     /**
691     * Get definitions of all properties of an object type.
692     *
693     * @param obj_type object type's name
694     * @return pairs of property name and property types
695     * @error
696     * API_EC_DATA_DATABASE_ERROR
697     * API_EC_PARAM
698     * API_EC_PERMISSION
699     * API_EC_DATA_OBJECT_NOT_FOUND
700     * API_EC_DATA_QUOTA_EXCEEDED
701     * API_EC_DATA_UNKNOWN_ERROR
702     */
703     public function data_getObjectType($obj_type) {
704     return $this->call_method
705     ('facebook.data.getObjectType',
706     array('obj_type' => $obj_type));
707     }
708    
709     /**
710     * Create a new object.
711     *
712     * @param obj_type object type's name
713     * @param properties (optional) properties to set initially
714     * @return newly created object's id
715     * @error
716     * API_EC_DATA_DATABASE_ERROR
717     * API_EC_PARAM
718     * API_EC_PERMISSION
719     * API_EC_DATA_INVALID_OPERATION
720     * API_EC_DATA_QUOTA_EXCEEDED
721     * API_EC_DATA_UNKNOWN_ERROR
722     */
723     public function data_createObject($obj_type, $properties = null) {
724     return $this->call_method
725     ('facebook.data.createObject',
726     array('obj_type' => $obj_type,
727     'properties' => json_encode($properties)));
728     }
729    
730     /**
731     * Update an existing object.
732     *
733     * @param obj_id object's id
734     * @param properties new properties
735     * @param replace true for replacing existing properties; false for merging
736     * @error
737     * API_EC_DATA_DATABASE_ERROR
738     * API_EC_DATA_OBJECT_NOT_FOUND
739     * API_EC_PARAM
740     * API_EC_PERMISSION
741     * API_EC_DATA_INVALID_OPERATION
742     * API_EC_DATA_QUOTA_EXCEEDED
743     * API_EC_DATA_UNKNOWN_ERROR
744     */
745     public function data_updateObject($obj_id, $properties, $replace = false) {
746     return $this->call_method
747     ('facebook.data.updateObject',
748     array('obj_id' => $obj_id,
749     'properties' => json_encode($properties),
750     'replace' => $replace));
751     }
752    
753     /**
754     * Delete an existing object.
755     *
756     * @param obj_id object's id
757     * @error
758     * API_EC_DATA_DATABASE_ERROR
759     * API_EC_DATA_OBJECT_NOT_FOUND
760     * API_EC_PARAM
761     * API_EC_PERMISSION
762     * API_EC_DATA_INVALID_OPERATION
763     * API_EC_DATA_QUOTA_EXCEEDED
764     * API_EC_DATA_UNKNOWN_ERROR
765     */
766     public function data_deleteObject($obj_id) {
767     return $this->call_method
768     ('facebook.data.deleteObject',
769     array('obj_id' => $obj_id));
770     }
771    
772     /**
773     * Delete a list of objects.
774     *
775     * @param obj_ids objects to delete
776     * @error
777     * API_EC_DATA_DATABASE_ERROR
778     * API_EC_PARAM
779     * API_EC_PERMISSION
780     * API_EC_DATA_INVALID_OPERATION
781     * API_EC_DATA_QUOTA_EXCEEDED
782     * API_EC_DATA_UNKNOWN_ERROR
783     */
784     public function data_deleteObjects($obj_ids) {
785     return $this->call_method
786     ('facebook.data.deleteObjects',
787     array('obj_ids' => json_encode($obj_ids)));
788     }
789    
790     /**
791     * Get a single property value of an object.
792     *
793     * @param obj_id object's id
794     * @param prop_name individual property's name
795     * @return individual property's value
796     * @error
797     * API_EC_DATA_DATABASE_ERROR
798     * API_EC_DATA_OBJECT_NOT_FOUND
799     * API_EC_PARAM
800     * API_EC_PERMISSION
801     * API_EC_DATA_INVALID_OPERATION
802     * API_EC_DATA_QUOTA_EXCEEDED
803     * API_EC_DATA_UNKNOWN_ERROR
804     */
805     public function data_getObjectProperty($obj_id, $prop_name) {
806     return $this->call_method
807     ('facebook.data.getObjectProperty',
808     array('obj_id' => $obj_id,
809     'prop_name' => $prop_name));
810     }
811    
812     /**
813     * Get properties of an object.
814     *
815     * @param obj_id object's id
816     * @param prop_names (optional) properties to return; null for all.
817     * @return specified properties of an object
818     * @error
819     * API_EC_DATA_DATABASE_ERROR
820     * API_EC_DATA_OBJECT_NOT_FOUND
821     * API_EC_PARAM
822     * API_EC_PERMISSION
823     * API_EC_DATA_INVALID_OPERATION
824     * API_EC_DATA_QUOTA_EXCEEDED
825     * API_EC_DATA_UNKNOWN_ERROR
826     */
827     public function data_getObject($obj_id, $prop_names = null) {
828     return $this->call_method
829     ('facebook.data.getObject',
830     array('obj_id' => $obj_id,
831     'prop_names' => json_encode($prop_names)));
832     }
833    
834     /**
835     * Get properties of a list of objects.
836     *
837     * @param obj_ids object ids
838     * @param prop_names (optional) properties to return; null for all.
839     * @return specified properties of an object
840     * @error
841     * API_EC_DATA_DATABASE_ERROR
842     * API_EC_DATA_OBJECT_NOT_FOUND
843     * API_EC_PARAM
844     * API_EC_PERMISSION
845     * API_EC_DATA_INVALID_OPERATION
846     * API_EC_DATA_QUOTA_EXCEEDED
847     * API_EC_DATA_UNKNOWN_ERROR
848     */
849     public function data_getObjects($obj_ids, $prop_names = null) {
850     return $this->call_method
851     ('facebook.data.getObjects',
852     array('obj_ids' => json_encode($obj_ids),
853     'prop_names' => json_encode($prop_names)));
854     }
855    
856     /**
857     * Set a single property value of an object.
858     *
859     * @param obj_id object's id
860     * @param prop_name individual property's name
861     * @param prop_value new value to set
862     * @error
863     * API_EC_DATA_DATABASE_ERROR
864     * API_EC_DATA_OBJECT_NOT_FOUND
865     * API_EC_PARAM
866     * API_EC_PERMISSION
867     * API_EC_DATA_INVALID_OPERATION
868     * API_EC_DATA_QUOTA_EXCEEDED
869     * API_EC_DATA_UNKNOWN_ERROR
870     */
871     public function data_setObjectProperty($obj_id, $prop_name,
872     $prop_value) {
873     return $this->call_method
874     ('facebook.data.setObjectProperty',
875     array('obj_id' => $obj_id,
876     'prop_name' => $prop_name,
877     'prop_value' => $prop_value));
878     }
879    
880     /**
881     * Read hash value by key.
882     *
883     * @param obj_type object type's name
884     * @param key hash key
885     * @param prop_name (optional) individual property's name
886     * @return hash value
887     * @error
888     * API_EC_DATA_DATABASE_ERROR
889     * API_EC_PARAM
890     * API_EC_PERMISSION
891     * API_EC_DATA_INVALID_OPERATION
892     * API_EC_DATA_QUOTA_EXCEEDED
893     * API_EC_DATA_UNKNOWN_ERROR
894     */
895     public function data_getHashValue($obj_type, $key, $prop_name = null) {
896     return $this->call_method
897     ('facebook.data.getHashValue',
898     array('obj_type' => $obj_type,
899     'key' => $key,
900     'prop_name' => $prop_name));
901     }
902    
903     /**
904     * Write hash value by key.
905     *
906     * @param obj_type object type's name
907     * @param key hash key
908     * @param value hash value
909     * @param prop_name (optional) individual property's name
910     * @error
911     * API_EC_DATA_DATABASE_ERROR
912     * API_EC_PARAM
913     * API_EC_PERMISSION
914     * API_EC_DATA_INVALID_OPERATION
915     * API_EC_DATA_QUOTA_EXCEEDED
916     * API_EC_DATA_UNKNOWN_ERROR
917     */
918     public function data_setHashValue($obj_type, $key, $value, $prop_name = null) {
919     return $this->call_method
920     ('facebook.data.setHashValue',
921     array('obj_type' => $obj_type,
922     'key' => $key,
923     'value' => $value,
924     'prop_name' => $prop_name));
925     }
926    
927     /**
928     * Increase a hash value by specified increment atomically.
929     *
930     * @param obj_type object type's name
931     * @param key hash key
932     * @param prop_name individual property's name
933     * @param increment (optional) default is 1
934     * @return incremented hash value
935     * @error
936     * API_EC_DATA_DATABASE_ERROR
937     * API_EC_PARAM
938     * API_EC_PERMISSION
939     * API_EC_DATA_INVALID_OPERATION
940     * API_EC_DATA_QUOTA_EXCEEDED
941     * API_EC_DATA_UNKNOWN_ERROR
942     */
943     public function data_incHashValue($obj_type, $key, $prop_name, $increment = 1) {
944     return $this->call_method
945     ('facebook.data.incHashValue',
946     array('obj_type' => $obj_type,
947     'key' => $key,
948     'prop_name' => $prop_name,
949     'increment' => $increment));
950     }
951    
952     /**
953     * Remove a hash key and its values.
954     *
955     * @param obj_type object type's name
956     * @param key hash key
957     * @error
958     * API_EC_DATA_DATABASE_ERROR
959     * API_EC_PARAM
960     * API_EC_PERMISSION
961     * API_EC_DATA_INVALID_OPERATION
962     * API_EC_DATA_QUOTA_EXCEEDED
963     * API_EC_DATA_UNKNOWN_ERROR
964     */
965     public function data_removeHashKey($obj_type, $key) {
966     return $this->call_method
967     ('facebook.data.removeHashKey',
968     array('obj_type' => $obj_type,
969     'key' => $key));
970     }
971    
972     /**
973     * Remove hash keys and their values.
974     *
975     * @param obj_type object type's name
976     * @param keys hash keys
977     * @error
978     * API_EC_DATA_DATABASE_ERROR
979     * API_EC_PARAM
980     * API_EC_PERMISSION
981     * API_EC_DATA_INVALID_OPERATION
982     * API_EC_DATA_QUOTA_EXCEEDED
983     * API_EC_DATA_UNKNOWN_ERROR
984     */
985     public function data_removeHashKeys($obj_type, $keys) {
986     return $this->call_method
987     ('facebook.data.removeHashKeys',
988     array('obj_type' => $obj_type,
989     'keys' => json_encode($keys)));
990     }
991    
992    
993     /**
994     * Define an object association.
995     *
996     * @param name name of this association
997     * @param assoc_type 1: one-way 2: two-way symmetric 3: two-way asymmetric
998     * @param assoc_info1 needed info about first object type
999     * @param assoc_info2 needed info about second object type
1000     * @param inverse (optional) name of reverse association
1001     * @error
1002     * API_EC_DATA_DATABASE_ERROR
1003     * API_EC_DATA_OBJECT_ALREADY_EXISTS
1004     * API_EC_PARAM
1005     * API_EC_PERMISSION
1006     * API_EC_DATA_INVALID_OPERATION
1007     * API_EC_DATA_QUOTA_EXCEEDED
1008     * API_EC_DATA_UNKNOWN_ERROR
1009     */
1010     public function data_defineAssociation($name, $assoc_type, $assoc_info1,
1011     $assoc_info2, $inverse = null) {
1012     return $this->call_method
1013     ('facebook.data.defineAssociation',
1014     array('name' => $name,
1015     'assoc_type' => $assoc_type,
1016     'assoc_info1' => json_encode($assoc_info1),
1017     'assoc_info2' => json_encode($assoc_info2),
1018     'inverse' => $inverse));
1019     }
1020    
1021     /**
1022     * Undefine an object association.
1023     *
1024     * @param name name of this association
1025     * @error
1026     * API_EC_DATA_DATABASE_ERROR
1027     * API_EC_DATA_OBJECT_NOT_FOUND
1028     * API_EC_PARAM
1029     * API_EC_PERMISSION
1030     * API_EC_DATA_INVALID_OPERATION
1031     * API_EC_DATA_QUOTA_EXCEEDED
1032     * API_EC_DATA_UNKNOWN_ERROR
1033     */
1034     public function data_undefineAssociation($name) {
1035     return $this->call_method
1036     ('facebook.data.undefineAssociation',
1037     array('name' => $name));
1038     }
1039    
1040     /**
1041     * Rename an object association or aliases.
1042     *
1043     * @param name name of this association
1044     * @param new_name (optional) new name of this association
1045     * @param new_alias1 (optional) new alias for object type 1
1046     * @param new_alias2 (optional) new alias for object type 2
1047     * @error
1048     * API_EC_DATA_DATABASE_ERROR
1049     * API_EC_DATA_OBJECT_ALREADY_EXISTS
1050     * API_EC_DATA_OBJECT_NOT_FOUND
1051     * API_EC_PARAM
1052     * API_EC_PERMISSION
1053     * API_EC_DATA_INVALID_OPERATION
1054     * API_EC_DATA_QUOTA_EXCEEDED
1055     * API_EC_DATA_UNKNOWN_ERROR
1056     */
1057     public function data_renameAssociation($name, $new_name, $new_alias1 = null,
1058     $new_alias2 = null) {
1059     return $this->call_method
1060     ('facebook.data.renameAssociation',
1061     array('name' => $name,
1062     'new_name' => $new_name,
1063     'new_alias1' => $new_alias1,
1064     'new_alias2' => $new_alias2));
1065     }
1066    
1067     /**
1068     * Get definition of an object association.
1069     *
1070     * @param name name of this association
1071     * @return specified association
1072     * @error
1073     * API_EC_DATA_DATABASE_ERROR
1074     * API_EC_DATA_OBJECT_NOT_FOUND
1075     * API_EC_PARAM
1076     * API_EC_PERMISSION
1077     * API_EC_DATA_QUOTA_EXCEEDED
1078     * API_EC_DATA_UNKNOWN_ERROR
1079     */
1080     public function data_getAssociationDefinition($name) {
1081     return $this->call_method
1082     ('facebook.data.getAssociationDefinition',
1083     array('name' => $name));
1084     }
1085    
1086     /**
1087     * Get definition of all associations.
1088     *
1089     * @return all defined associations
1090     * @error
1091     * API_EC_DATA_DATABASE_ERROR
1092     * API_EC_PERMISSION
1093     * API_EC_DATA_QUOTA_EXCEEDED
1094     * API_EC_DATA_UNKNOWN_ERROR
1095     */
1096     public function data_getAssociationDefinitions() {
1097     return $this->call_method
1098     ('facebook.data.getAssociationDefinitions',
1099     array());
1100     }
1101    
1102     /**
1103     * Create or modify an association between two objects.
1104     *
1105     * @param name name of association
1106     * @param obj_id1 id of first object
1107     * @param obj_id2 id of second object
1108     * @param data (optional) extra string data to store
1109     * @param assoc_time (optional) extra time data; default to creation time
1110     * @error
1111     * API_EC_DATA_DATABASE_ERROR
1112     * API_EC_PARAM
1113     * API_EC_PERMISSION
1114     * API_EC_DATA_INVALID_OPERATION
1115     * API_EC_DATA_QUOTA_EXCEEDED
1116     * API_EC_DATA_UNKNOWN_ERROR
1117     */
1118     public function data_setAssociation($name, $obj_id1, $obj_id2, $data = null,
1119     $assoc_time = null) {
1120     return $this->call_method
1121     ('facebook.data.setAssociation',
1122     array('name' => $name,
1123     'obj_id1' => $obj_id1,
1124     'obj_id2' => $obj_id2,
1125     'data' => $data,
1126     'assoc_time' => $assoc_time));
1127     }
1128    
1129     /**
1130     * Create or modify associations between objects.
1131     *
1132     * @param assocs associations to set
1133     * @param name (optional) name of association
1134     * @error
1135     * API_EC_DATA_DATABASE_ERROR
1136     * API_EC_PARAM
1137     * API_EC_PERMISSION
1138     * API_EC_DATA_INVALID_OPERATION
1139     * API_EC_DATA_QUOTA_EXCEEDED
1140     * API_EC_DATA_UNKNOWN_ERROR
1141     */
1142     public function data_setAssociations($assocs, $name = null) {
1143     return $this->call_method
1144     ('facebook.data.setAssociations',
1145     array('assocs' => json_encode($assocs),
1146     'name' => $name));
1147     }
1148    
1149     /**
1150     * Remove an association between two objects.
1151     *
1152     * @param name name of association
1153     * @param obj_id1 id of first object
1154     * @param obj_id2 id of second object
1155     * @error
1156     * API_EC_DATA_DATABASE_ERROR
1157     * API_EC_DATA_OBJECT_NOT_FOUND
1158     * API_EC_PARAM
1159     * API_EC_PERMISSION
1160     * API_EC_DATA_QUOTA_EXCEEDED
1161     * API_EC_DATA_UNKNOWN_ERROR
1162     */
1163     public function data_removeAssociation($name, $obj_id1, $obj_id2) {
1164     return $this->call_method
1165     ('facebook.data.removeAssociation',
1166     array('obj_id1' => $obj_id1,
1167     'obj_id2' => $obj_id2));
1168     }
1169    
1170     /**
1171     * Remove associations between objects by specifying pairs of object ids.
1172     *
1173     * @param assocs associations to remove
1174     * @param name (optional) name of association
1175     * @error
1176     * API_EC_DATA_DATABASE_ERROR
1177     * API_EC_DATA_OBJECT_NOT_FOUND
1178     * API_EC_PARAM
1179     * API_EC_PERMISSION
1180     * API_EC_DATA_QUOTA_EXCEEDED
1181     * API_EC_DATA_UNKNOWN_ERROR
1182     */
1183     public function data_removeAssociations($assocs, $name = null) {
1184     return $this->call_method
1185     ('facebook.data.removeAssociations',
1186     array('assocs' => json_encode($assocs),
1187     'name' => $name));
1188     }
1189    
1190     /**
1191     * Remove associations between objects by specifying one object id.
1192     *
1193     * @param name name of association
1194     * @param obj_id who's association to remove
1195     * @error
1196     * API_EC_DATA_DATABASE_ERROR
1197     * API_EC_DATA_OBJECT_NOT_FOUND
1198     * API_EC_PARAM
1199     * API_EC_PERMISSION
1200     * API_EC_DATA_INVALID_OPERATION
1201     * API_EC_DATA_QUOTA_EXCEEDED
1202     * API_EC_DATA_UNKNOWN_ERROR
1203     */
1204     public function data_removeAssociatedObjects($name, $obj_id) {
1205     return $this->call_method
1206     ('facebook.data.removeAssociatedObjects',
1207     array('name' => $name,
1208     'obj_id' => $obj_id));
1209     }
1210    
1211     /**
1212     * Retrieve a list of associated objects.
1213     *
1214     * @param name name of association
1215     * @param obj_id who's association to retrieve
1216     * @param no_data only return object ids
1217     * @return associated objects
1218     * @error
1219     * API_EC_DATA_DATABASE_ERROR
1220     * API_EC_DATA_OBJECT_NOT_FOUND
1221     * API_EC_PARAM
1222     * API_EC_PERMISSION
1223     * API_EC_DATA_INVALID_OPERATION
1224     * API_EC_DATA_QUOTA_EXCEEDED
1225     * API_EC_DATA_UNKNOWN_ERROR
1226     */
1227     public function data_getAssociatedObjects($name, $obj_id, $no_data = true) {
1228     return $this->call_method
1229     ('facebook.data.getAssociatedObjects',
1230     array('obj_id' => $obj_id,
1231     'no_data' => $no_data));
1232     }
1233    
1234     /**
1235     * Count associated objects.
1236     *
1237     * @param name name of association
1238     * @param obj_id who's association to retrieve
1239     * @return associated object's count
1240     * @error
1241     * API_EC_DATA_DATABASE_ERROR
1242     * API_EC_DATA_OBJECT_NOT_FOUND
1243     * API_EC_PARAM
1244     * API_EC_PERMISSION
1245     * API_EC_DATA_INVALID_OPERATION
1246     * API_EC_DATA_QUOTA_EXCEEDED
1247     * API_EC_DATA_UNKNOWN_ERROR
1248     */
1249     public function data_getAssociatedObjectCount($name, $obj_id) {
1250     return $this->call_method
1251     ('facebook.data.getAssociatedObjectCount',
1252     array('name' => $name,
1253     'obj_id' => $obj_id));
1254     }
1255    
1256     /**
1257     * Get a list of associated object counts.
1258     *
1259     * @param name name of association
1260     * @param obj_ids whose association to retrieve
1261     * @return associated object counts
1262     * @error
1263     * API_EC_DATA_DATABASE_ERROR
1264     * API_EC_DATA_OBJECT_NOT_FOUND
1265     * API_EC_PARAM
1266     * API_EC_PERMISSION
1267     * API_EC_DATA_INVALID_OPERATION
1268     * API_EC_DATA_QUOTA_EXCEEDED
1269     * API_EC_DATA_UNKNOWN_ERROR
1270     */
1271     public function data_getAssociatedObjectCounts($name, $obj_ids) {
1272     return $this->call_method
1273     ('facebook.data.getAssociatedObjectCounts',
1274     array('name' => $name,
1275     'obj_ids' => json_encode($obj_ids)));
1276     }
1277    
1278     /**
1279     * Find all associations between two objects.
1280     *
1281     * @param obj_id1 id of first object
1282     * @param obj_id2 id of second object
1283     * @param no_data only return association names without data
1284     * @return all associations between objects
1285     * @error
1286     * API_EC_DATA_DATABASE_ERROR
1287     * API_EC_PARAM
1288     * API_EC_PERMISSION
1289     * API_EC_DATA_QUOTA_EXCEEDED
1290     * API_EC_DATA_UNKNOWN_ERROR
1291     */
1292     public function data_getAssociations($obj_id1, $obj_id2, $no_data = true) {
1293     return $this->call_method
1294     ('facebook.data.getAssociations',
1295     array('obj_id1' => $obj_id1,
1296     'obj_id2' => $obj_id2,
1297     'no_data' => $no_data));
1298     }
1299    
1300 douglas 943 /* UTILITY FUNCTIONS */
1301    
1302     public function call_method($method, $params) {
1303 douglas 946 if ($this->json) {
1304     $json = $this->post_request($method, $params);
1305     # XXX: silly facebook with its invalid JSON
1306     $valid = preg_match('/^[\[{].*[\]}]$/', $json);
1307     $array = json_decode($valid ? $json : "[$json]", true);
1308     $result = $valid ? $array : $array[0];
1309     } else {
1310     $xml = $this->post_request($method, $params);
1311     $sxml = simplexml_load_string($xml);
1312     $result = self::convert_simplexml_to_array($sxml);
1313     if ($GLOBALS['facebook_config']['debug']) {
1314     // output the raw xml and its corresponding php object, for debugging:
1315     print '<div style="margin: 10px 30px; padding: 5px; border: 2px solid black; background: gray; color: white; font-size: 12px; font-weight: bold;">';
1316     $this->cur_id++;
1317     print $this->cur_id . ': Called ' . $method . ', show ' .
1318     '<a href=# onclick="return toggleDisplay(' . $this->cur_id . ', \'params\');">Params</a> | '.
1319     '<a href=# onclick="return toggleDisplay(' . $this->cur_id . ', \'xml\');">XML</a> | '.
1320     '<a href=# onclick="return toggleDisplay(' . $this->cur_id . ', \'sxml\');">SXML</a> | '.
1321     '<a href=# onclick="return toggleDisplay(' . $this->cur_id . ', \'php\');">PHP</a>';
1322     print '<pre id="params'.$this->cur_id.'" style="display: none; overflow: auto;">'.print_r($params, true).'</pre>';
1323     print '<pre id="xml'.$this->cur_id.'" style="display: none; overflow: auto;">'.htmlspecialchars($xml).'</pre>';
1324     print '<pre id="php'.$this->cur_id.'" style="display: none; overflow: auto;">'.print_r($result, true).'</pre>';
1325     print '<pre id="sxml'.$this->cur_id.'" style="display: none; overflow: auto;">'.print_r($sxml, true).'</pre>';
1326     print '</div>';
1327     }
1328 douglas 943 }
1329     if (is_array($result) && isset($result['error_code'])) {
1330     throw new FacebookRestClientException($result['error_msg'], $result['error_code']);
1331     }
1332     return $result;
1333     }
1334    
1335     public function post_request($method, $params) {
1336     $params['method'] = $method;
1337     $params['session_key'] = $this->session_key;
1338     $params['api_key'] = $this->api_key;
1339     $params['call_id'] = microtime(true);
1340     if ($params['call_id'] <= $this->last_call_id) {
1341     $params['call_id'] = $this->last_call_id + 0.001;
1342     }
1343     $this->last_call_id = $params['call_id'];
1344     if (!isset($params['v'])) {
1345     $params['v'] = '1.0';
1346     }
1347 douglas 946 if ($this->json)
1348     $params['format'] = 'JSON';
1349 douglas 943 $post_params = array();
1350     foreach ($params as $key => &$val) {
1351     if (is_array($val)) $val = implode(',', $val);
1352     $post_params[] = $key.'='.urlencode($val);
1353     }
1354 douglas 946 $post_params[] = 'sig='.Facebook::generate_sig($params, $this->secret);
1355 douglas 943 $post_string = implode('&', $post_params);
1356    
1357 douglas 946 if ($this->json) {
1358     $result = file_get_contents($this->server_addr, false, stream_context_create(
1359     array('http' =>
1360     array('method' => 'POST',
1361     'header' => 'Content-type: application/x-www-form-urlencoded'."\r\n".
1362     'User-Agent: Facebook API PHP5 Client 1.1 (non-curl) '.phpversion()."\r\n".
1363     'Content-length: ' . strlen($post_string),
1364     'content' => $post_string))));
1365     } elseif (function_exists('curl_init')) {
1366 douglas 943 // Use CURL if installed...
1367     $ch = curl_init();
1368     curl_setopt($ch, CURLOPT_URL, $this->server_addr);
1369     curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string);
1370     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
1371     curl_setopt($ch, CURLOPT_USERAGENT, 'Facebook API PHP5 Client 1.1 (curl) ' . phpversion());
1372     $result = curl_exec($ch);
1373     curl_close($ch);
1374     } else {
1375     // Non-CURL based version...
1376     $context =
1377     array('http' =>
1378     array('method' => 'POST',
1379     'header' => 'Content-type: application/x-www-form-urlencoded'."\r\n".
1380     'User-Agent: Facebook API PHP5 Client 1.1 (non-curl) '.phpversion()."\r\n".
1381     'Content-length: ' . strlen($post_string),
1382     'content' => $post_string));
1383     $contextid=stream_context_create($context);
1384     $sock=fopen($this->server_addr, 'r', false, $contextid);
1385     if ($sock) {
1386     $result='';
1387     while (!feof($sock))
1388     $result.=fgets($sock, 4096);
1389    
1390     fclose($sock);
1391     }
1392     }
1393     return $result;
1394     }
1395    
1396     public static function convert_simplexml_to_array($sxml) {
1397     $arr = array();
1398     if ($sxml) {
1399     foreach ($sxml as $k => $v) {
1400     if ($sxml['list']) {
1401     $arr[] = self::convert_simplexml_to_array($v);
1402     } else {
1403     $arr[$k] = self::convert_simplexml_to_array($v);
1404     }
1405     }
1406     }
1407     if (sizeof($arr) > 0) {
1408     return $arr;
1409     } else {
1410     return (string)$sxml;
1411     }
1412     }
1413     }
1414    
1415     class FacebookRestClientException extends Exception {
1416     }
1417    
1418     // Supporting methods and values------
1419    
1420     /**
1421     * Error codes and descriptions for the Facebook API.
1422     */
1423    
1424     class FacebookAPIErrorCodes {
1425    
1426     const API_EC_SUCCESS = 0;
1427    
1428     /*
1429     * GENERAL ERRORS
1430     */
1431     const API_EC_UNKNOWN = 1;
1432     const API_EC_SERVICE = 2;
1433     const API_EC_METHOD = 3;
1434     const API_EC_TOO_MANY_CALLS = 4;
1435     const API_EC_BAD_IP = 5;
1436    
1437     /*
1438     * PARAMETER ERRORS
1439     */
1440     const API_EC_PARAM = 100;
1441     const API_EC_PARAM_API_KEY = 101;
1442     const API_EC_PARAM_SESSION_KEY = 102;
1443     const API_EC_PARAM_CALL_ID = 103;
1444     const API_EC_PARAM_SIGNATURE = 104;
1445     const API_EC_PARAM_USER_ID = 110;
1446     const API_EC_PARAM_USER_FIELD = 111;
1447     const API_EC_PARAM_SOCIAL_FIELD = 112;
1448     const API_EC_PARAM_ALBUM_ID = 120;
1449    
1450     /*
1451     * USER PERMISSIONS ERRORS
1452     */
1453     const API_EC_PERMISSION = 200;
1454     const API_EC_PERMISSION_USER = 210;
1455     const API_EC_PERMISSION_ALBUM = 220;
1456     const API_EC_PERMISSION_PHOTO = 221;
1457    
1458     const FQL_EC_PARSER = 601;
1459     const FQL_EC_UNKNOWN_FIELD = 602;
1460     const FQL_EC_UNKNOWN_TABLE = 603;
1461     const FQL_EC_NOT_INDEXABLE = 604;
1462 douglas 956
1463     /**
1464     * DATA STORE API ERRORS
1465     */
1466     const API_EC_DATA_UNKNOWN_ERROR = 800;
1467     const API_EC_DATA_INVALID_OPERATION = 801;
1468     const API_EC_DATA_QUOTA_EXCEEDED = 802;
1469     const API_EC_DATA_OBJECT_NOT_FOUND = 803;
1470     const API_EC_DATA_OBJECT_ALREADY_EXISTS = 804;
1471     const API_EC_DATA_DATABASE_ERROR = 805;
1472 douglas 943
1473     public static $api_error_descriptions = array(
1474     API_EC_SUCCESS => 'Success',
1475     API_EC_UNKNOWN => 'An unknown error occurred',
1476     API_EC_SERVICE => 'Service temporarily unavailable',
1477     API_EC_METHOD => 'Unknown method',
1478     API_EC_TOO_MANY_CALLS => 'Application request limit reached',
1479     API_EC_BAD_IP => 'Unauthorized source IP address',
1480     API_EC_PARAM => 'Invalid parameter',
1481     API_EC_PARAM_API_KEY => 'Invalid API key',
1482     API_EC_PARAM_SESSION_KEY => 'Session key invalid or no longer valid',
1483     API_EC_PARAM_CALL_ID => 'Call_id must be greater than previous',
1484     API_EC_PARAM_SIGNATURE => 'Incorrect signature',
1485     API_EC_PARAM_USER_ID => 'Invalid user id',
1486     API_EC_PARAM_USER_FIELD => 'Invalid user info field',
1487     API_EC_PARAM_SOCIAL_FIELD => 'Invalid user field',
1488     API_EC_PARAM_ALBUM_ID => 'Invalid album id',
1489     API_EC_PERMISSION => 'Permissions error',
1490     API_EC_PERMISSION_USER => 'User not visible',
1491     API_EC_PERMISSION_ALBUM => 'Album not visible',
1492     API_EC_PERMISSION_PHOTO => 'Photo not visible',
1493     FQL_EC_PARSER => 'FQL: Parser Error',
1494     FQL_EC_UNKNOWN_FIELD => 'FQL: Unknown Field',
1495     FQL_EC_UNKNOWN_TABLE => 'FQL: Unknown Table',
1496     FQL_EC_NOT_INDEXABLE => 'FQL: Statement not indexable',
1497     FQL_EC_UNKNOWN_FUNCTION => 'FQL: Attempted to call unknown function',
1498     FQL_EC_INVALID_PARAM => 'FQL: Invalid parameter passed in',
1499 douglas 956 API_EC_DATA_UNKNOWN_ERROR => 'Unknown data store API error',
1500     API_EC_DATA_INVALID_OPERATION => 'Invalid operation',
1501     API_EC_DATA_QUOTA_EXCEEDED => 'Data store allowable quota was exceeded',
1502     API_EC_DATA_OBJECT_NOT_FOUND => 'Specified object cannot be found',
1503     API_EC_DATA_OBJECT_ALREADY_EXISTS => 'Specified object already exists',
1504     API_EC_DATA_DATABASE_ERROR => 'A database error occurred. Please try again',
1505 douglas 943 );
1506     }
1507    
1508     $profile_field_array = array(
1509     "about_me",
1510     "activities",
1511     "affiliations",
1512     "birthday",
1513     "books",
1514     "current_location",
1515     "education_history",
1516     "first_name",
1517     "hometown_location",
1518     "hs_info",
1519     "interests",
1520     "is_app_user",
1521     "last_name",
1522     "meeting_for",
1523     "meeting_sex",
1524     "movies",
1525     "music",
1526     "name",
1527     "notes_count",
1528     "pic",
1529     "pic_big",
1530     "pic_small",
1531     "political",
1532     "profile_update_time",
1533     "quotes",
1534     "relationship_status",
1535     "religion",
1536     "sex",
1537     "significant_other_id",
1538     "status",
1539     "timezone",
1540     "tv",
1541     "wall_count",
1542     "work_history");
1543     ?>

Properties

Name Value
svn:keywords Id