ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/facebook/trunk/facebookapi_php5_restlib.php
Revision: 981
Committed: 2008-01-16T16:47:47-08:00 (17 years, 5 months ago) by douglas
File size: 56418 byte(s)
Log Message:
Merged with 2007-12-20!

File Contents

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

Properties

Name Value
svn:keywords Id