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

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

Properties

Name Value
svn:keywords Id