PageRenderTime 1172ms CodeModel.GetById 42ms RepoModel.GetById 5ms app.codeStats 1ms

/extlib/facebook/facebookapi_php5_restlib.php

https://github.com/Br3nda/laconica
PHP | 3400 lines | 1407 code | 246 blank | 1747 comment | 69 complexity | 1c15fefac4225ec78f4ff1a775533848 MD5 | raw file
Possible License(s): AGPL-3.0
  1. <?php
  2. // Copyright 2004-2009 Facebook. All Rights Reserved.
  3. //
  4. // +---------------------------------------------------------------------------+
  5. // | Facebook Platform PHP5 client |
  6. // +---------------------------------------------------------------------------+
  7. // | Copyright (c) 2007-2009 Facebook, Inc. |
  8. // | All rights reserved. |
  9. // | |
  10. // | Redistribution and use in source and binary forms, with or without |
  11. // | modification, are permitted provided that the following conditions |
  12. // | are met: |
  13. // | |
  14. // | 1. Redistributions of source code must retain the above copyright |
  15. // | notice, this list of conditions and the following disclaimer. |
  16. // | 2. Redistributions in binary form must reproduce the above copyright |
  17. // | notice, this list of conditions and the following disclaimer in the |
  18. // | documentation and/or other materials provided with the distribution. |
  19. // | |
  20. // | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
  21. // | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
  22. // | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
  23. // | IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
  24. // | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
  25. // | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
  26. // | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
  27. // | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
  28. // | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
  29. // | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
  30. // +---------------------------------------------------------------------------+
  31. // | For help with this library, contact developers-help@facebook.com |
  32. // +---------------------------------------------------------------------------+
  33. //
  34. include_once 'jsonwrapper/jsonwrapper.php';
  35. class FacebookRestClient {
  36. public $secret;
  37. public $session_key;
  38. public $api_key;
  39. // to save making the friends.get api call, this will get prepopulated on
  40. // canvas pages
  41. public $friends_list;
  42. public $user;
  43. // to save making the pages.isAppAdded api call, this will get prepopulated
  44. // on canvas pages
  45. public $added;
  46. public $is_user;
  47. // we don't pass friends list to iframes, but we want to make
  48. // friends_get really simple in the canvas_user (non-logged in) case.
  49. // So we use the canvas_user as default arg to friends_get
  50. public $canvas_user;
  51. public $batch_mode;
  52. private $batch_queue;
  53. private $pending_batch;
  54. private $call_as_apikey;
  55. private $use_curl_if_available;
  56. const BATCH_MODE_DEFAULT = 0;
  57. const BATCH_MODE_SERVER_PARALLEL = 0;
  58. const BATCH_MODE_SERIAL_ONLY = 2;
  59. /**
  60. * Create the client.
  61. * @param string $session_key if you haven't gotten a session key yet, leave
  62. * this as null and then set it later by just
  63. * directly accessing the $session_key member
  64. * variable.
  65. */
  66. public function __construct($api_key, $secret, $session_key=null) {
  67. $this->secret = $secret;
  68. $this->session_key = $session_key;
  69. $this->api_key = $api_key;
  70. $this->batch_mode = FacebookRestClient::BATCH_MODE_DEFAULT;
  71. $this->last_call_id = 0;
  72. $this->call_as_apikey = '';
  73. $this->use_curl_if_available = true;
  74. $this->server_addr = Facebook::get_facebook_url('api') . '/restserver.php';
  75. if (!empty($GLOBALS['facebook_config']['debug'])) {
  76. $this->cur_id = 0;
  77. ?>
  78. <script type="text/javascript">
  79. var types = ['params', 'xml', 'php', 'sxml'];
  80. function getStyle(elem, style) {
  81. if (elem.getStyle) {
  82. return elem.getStyle(style);
  83. } else {
  84. return elem.style[style];
  85. }
  86. }
  87. function setStyle(elem, style, value) {
  88. if (elem.setStyle) {
  89. elem.setStyle(style, value);
  90. } else {
  91. elem.style[style] = value;
  92. }
  93. }
  94. function toggleDisplay(id, type) {
  95. for (var i = 0; i < types.length; i++) {
  96. var t = types[i];
  97. var pre = document.getElementById(t + id);
  98. if (pre) {
  99. if (t != type || getStyle(pre, 'display') == 'block') {
  100. setStyle(pre, 'display', 'none');
  101. } else {
  102. setStyle(pre, 'display', 'block');
  103. }
  104. }
  105. }
  106. return false;
  107. }
  108. </script>
  109. <?php
  110. }
  111. }
  112. /**
  113. * Set the default user id for methods that allow the caller
  114. * to pass an uid parameter to identify the target user
  115. * instead of a session key. This currently applies to
  116. * the user preferences methods.
  117. *
  118. * @param $uid int the user id
  119. */
  120. public function set_user($uid) {
  121. $this->user = $uid;
  122. }
  123. /**
  124. * Normally, if the cURL library/PHP extension is available, it is used for
  125. * HTTP transactions. This allows that behavior to be overridden, falling
  126. * back to a vanilla-PHP implementation even if cURL is installed.
  127. *
  128. * @param $use_curl_if_available bool whether or not to use cURL if available
  129. */
  130. public function set_use_curl_if_available($use_curl_if_available) {
  131. $this->use_curl_if_available = $use_curl_if_available;
  132. }
  133. /**
  134. * Start a batch operation.
  135. */
  136. public function begin_batch() {
  137. if ($this->pending_batch()) {
  138. $code = FacebookAPIErrorCodes::API_EC_BATCH_ALREADY_STARTED;
  139. $description = FacebookAPIErrorCodes::$api_error_descriptions[$code];
  140. throw new FacebookRestClientException($description, $code);
  141. }
  142. $this->batch_queue = array();
  143. $this->pending_batch = true;
  144. }
  145. /*
  146. * End current batch operation
  147. */
  148. public function end_batch() {
  149. if (!$this->pending_batch()) {
  150. $code = FacebookAPIErrorCodes::API_EC_BATCH_NOT_STARTED;
  151. $description = FacebookAPIErrorCodes::$api_error_descriptions[$code];
  152. throw new FacebookRestClientException($description, $code);
  153. }
  154. $this->pending_batch = false;
  155. $this->execute_server_side_batch();
  156. $this->batch_queue = null;
  157. }
  158. /**
  159. * are we currently queueing up calls for a batch?
  160. */
  161. public function pending_batch() {
  162. return $this->pending_batch;
  163. }
  164. private function execute_server_side_batch() {
  165. $item_count = count($this->batch_queue);
  166. $method_feed = array();
  167. foreach($this->batch_queue as $batch_item) {
  168. $method = $batch_item['m'];
  169. $params = $batch_item['p'];
  170. $this->finalize_params($method, $params);
  171. $method_feed[] = $this->create_post_string($method, $params);
  172. }
  173. $method_feed_json = json_encode($method_feed);
  174. $serial_only =
  175. ($this->batch_mode == FacebookRestClient::BATCH_MODE_SERIAL_ONLY);
  176. $params = array('method_feed' => $method_feed_json,
  177. 'serial_only' => $serial_only);
  178. if ($this->call_as_apikey) {
  179. $params['call_as_apikey'] = $this->call_as_apikey;
  180. }
  181. $xml = $this->post_request('batch.run', $params);
  182. $result = $this->convert_xml_to_result($xml, 'batch.run', $params);
  183. if (is_array($result) && isset($result['error_code'])) {
  184. throw new FacebookRestClientException($result['error_msg'],
  185. $result['error_code']);
  186. }
  187. for($i = 0; $i < $item_count; $i++) {
  188. $batch_item = $this->batch_queue[$i];
  189. $batch_item_result_xml = $result[$i];
  190. $batch_item_result = $this->convert_xml_to_result($batch_item_result_xml,
  191. $batch_item['m'],
  192. $batch_item['p']);
  193. if (is_array($batch_item_result) &&
  194. isset($batch_item_result['error_code'])) {
  195. throw new FacebookRestClientException($batch_item_result['error_msg'],
  196. $batch_item_result['error_code']);
  197. }
  198. $batch_item['r'] = $batch_item_result;
  199. }
  200. }
  201. public function begin_permissions_mode($permissions_apikey) {
  202. $this->call_as_apikey = $permissions_apikey;
  203. }
  204. public function end_permissions_mode() {
  205. $this->call_as_apikey = '';
  206. }
  207. /*
  208. * If a page is loaded via HTTPS, then all images and static
  209. * resources need to be printed with HTTPS urls to avoid
  210. * mixed content warnings. If your page loads with an HTTPS
  211. * url, then call set_use_ssl_resources to retrieve the correct
  212. * urls.
  213. */
  214. public function set_use_ssl_resources($is_ssl = true) {
  215. $this->use_ssl_resources = $is_ssl;
  216. }
  217. /**
  218. * Returns public information for an application (as shown in the application
  219. * directory) by either application ID, API key, or canvas page name.
  220. *
  221. * @param int $application_id (Optional) app id
  222. * @param string $application_api_key (Optional) api key
  223. * @param string $application_canvas_name (Optional) canvas name
  224. *
  225. * Exactly one argument must be specified, otherwise it is an error.
  226. *
  227. * @return array An array of public information about the application.
  228. */
  229. public function application_getPublicInfo($application_id=null,
  230. $application_api_key=null,
  231. $application_canvas_name=null) {
  232. return $this->call_method('facebook.application.getPublicInfo',
  233. array('application_id' => $application_id,
  234. 'application_api_key' => $application_api_key,
  235. 'application_canvas_name' => $application_canvas_name));
  236. }
  237. /**
  238. * Creates an authentication token to be used as part of the desktop login
  239. * flow. For more information, please see
  240. * http://wiki.developers.facebook.com/index.php/Auth.createToken.
  241. *
  242. * @return string An authentication token.
  243. */
  244. public function auth_createToken() {
  245. return $this->call_method('facebook.auth.createToken');
  246. }
  247. /**
  248. * Returns the session information available after current user logs in.
  249. *
  250. * @param string $auth_token the token returned by
  251. * auth_createToken or passed back to
  252. * your callback_url.
  253. * @param bool $generate_session_secret whether the session returned should
  254. * include a session secret
  255. *
  256. * @return array An assoc array containing session_key, uid
  257. */
  258. public function auth_getSession($auth_token, $generate_session_secret=false) {
  259. if (!$this->pending_batch()) {
  260. $result = $this->call_method('facebook.auth.getSession',
  261. array('auth_token' => $auth_token,
  262. 'generate_session_secret' => $generate_session_secret));
  263. $this->session_key = $result['session_key'];
  264. if (!empty($result['secret']) && !$generate_session_secret) {
  265. // desktop apps have a special secret
  266. $this->secret = $result['secret'];
  267. }
  268. return $result;
  269. }
  270. }
  271. /**
  272. * Generates a session-specific secret. This is for integration with
  273. * client-side API calls, such as the JS library.
  274. *
  275. * @return array A session secret for the current promoted session
  276. *
  277. * @error API_EC_PARAM_SESSION_KEY
  278. * API_EC_PARAM_UNKNOWN
  279. */
  280. public function auth_promoteSession() {
  281. return $this->call_method('facebook.auth.promoteSession');
  282. }
  283. /**
  284. * Expires the session that is currently being used. If this call is
  285. * successful, no further calls to the API (which require a session) can be
  286. * made until a valid session is created.
  287. *
  288. * @return bool true if session expiration was successful, false otherwise
  289. */
  290. public function auth_expireSession() {
  291. return $this->call_method('facebook.auth.expireSession');
  292. }
  293. /**
  294. * Revokes the given extended permission that the user granted at some
  295. * prior time (for instance, offline_access or email). If no user is
  296. * provided, it will be revoked for the user of the current session.
  297. *
  298. * @param string $perm The permission to revoke
  299. * @param int $uid The user for whom to revoke the permission.
  300. */
  301. public function auth_revokeExtendedPermission($perm, $uid=null) {
  302. return $this->call_method('facebook.auth.revokeExtendedPermission',
  303. array('perm' => $perm, 'uid' => $uid));
  304. }
  305. /**
  306. * Revokes the user's agreement to the Facebook Terms of Service for your
  307. * application. If you call this method for one of your users, you will no
  308. * longer be able to make API requests on their behalf until they again
  309. * authorize your application. Use with care. Note that if this method is
  310. * called without a user parameter, then it will revoke access for the
  311. * current session's user.
  312. *
  313. * @param int $uid (Optional) User to revoke
  314. *
  315. * @return bool true if revocation succeeds, false otherwise
  316. */
  317. public function auth_revokeAuthorization($uid=null) {
  318. return $this->call_method('facebook.auth.revokeAuthorization',
  319. array('uid' => $uid));
  320. }
  321. /**
  322. * Get public key that is needed to verify digital signature
  323. * an app may pass to other apps. The public key is only used by
  324. * other apps for verification purposes.
  325. * @param string API key of an app
  326. * @return string The public key for the app.
  327. */
  328. public function auth_getAppPublicKey($target_app_key) {
  329. return $this->call_method('facebook.auth.getAppPublicKey',
  330. array('target_app_key' => $target_app_key));
  331. }
  332. /**
  333. * Get a structure that can be passed to another app
  334. * as proof of session. The other app can verify it using public
  335. * key of this app.
  336. *
  337. * @return signed public session data structure.
  338. */
  339. public function auth_getSignedPublicSessionData() {
  340. return $this->call_method('facebook.auth.getSignedPublicSessionData',
  341. array());
  342. }
  343. /**
  344. * Returns the number of unconnected friends that exist in this application.
  345. * This number is determined based on the accounts registered through
  346. * connect.registerUsers() (see below).
  347. */
  348. public function connect_getUnconnectedFriendsCount() {
  349. return $this->call_method('facebook.connect.getUnconnectedFriendsCount',
  350. array());
  351. }
  352. /**
  353. * This method is used to create an association between an external user
  354. * account and a Facebook user account, as per Facebook Connect.
  355. *
  356. * This method takes an array of account data, including a required email_hash
  357. * and optional account data. For each connected account, if the user exists,
  358. * the information is added to the set of the user's connected accounts.
  359. * If the user has already authorized the site, the connected account is added
  360. * in the confirmed state. If the user has not yet authorized the site, the
  361. * connected account is added in the pending state.
  362. *
  363. * This is designed to help Facebook Connect recognize when two Facebook
  364. * friends are both members of a external site, but perhaps are not aware of
  365. * it. The Connect dialog (see fb:connect-form) is used when friends can be
  366. * identified through these email hashes. See the following url for details:
  367. *
  368. * http://wiki.developers.facebook.com/index.php/Connect.registerUsers
  369. *
  370. * @param mixed $accounts A (JSON-encoded) array of arrays, where each array
  371. * has three properties:
  372. * 'email_hash' (req) - public email hash of account
  373. * 'account_id' (opt) - remote account id;
  374. * 'account_url' (opt) - url to remote account;
  375. *
  376. * @return array The list of email hashes for the successfully registered
  377. * accounts.
  378. */
  379. public function connect_registerUsers($accounts) {
  380. return $this->call_method('facebook.connect.registerUsers',
  381. array('accounts' => $accounts));
  382. }
  383. /**
  384. * Unregisters a set of accounts registered using connect.registerUsers.
  385. *
  386. * @param array $email_hashes The (JSON-encoded) list of email hashes to be
  387. * unregistered.
  388. *
  389. * @return array The list of email hashes which have been successfully
  390. * unregistered.
  391. */
  392. public function connect_unregisterUsers($email_hashes) {
  393. return $this->call_method('facebook.connect.unregisterUsers',
  394. array('email_hashes' => $email_hashes));
  395. }
  396. /**
  397. * Returns events according to the filters specified.
  398. *
  399. * @param int $uid (Optional) User associated with events. A null
  400. * parameter will default to the session user.
  401. * @param array/string $eids (Optional) Filter by these event
  402. * ids. A null parameter will get all events for
  403. * the user. (A csv list will work but is deprecated)
  404. * @param int $start_time (Optional) Filter with this unix time as lower
  405. * bound. A null or zero parameter indicates no
  406. * lower bound.
  407. * @param int $end_time (Optional) Filter with this UTC as upper bound.
  408. * A null or zero parameter indicates no upper
  409. * bound.
  410. * @param string $rsvp_status (Optional) Only show events where the given uid
  411. * has this rsvp status. This only works if you
  412. * have specified a value for $uid. Values are as
  413. * in events.getMembers. Null indicates to ignore
  414. * rsvp status when filtering.
  415. *
  416. * @return array The events matching the query.
  417. */
  418. public function &events_get($uid=null,
  419. $eids=null,
  420. $start_time=null,
  421. $end_time=null,
  422. $rsvp_status=null) {
  423. return $this->call_method('facebook.events.get',
  424. array('uid' => $uid,
  425. 'eids' => $eids,
  426. 'start_time' => $start_time,
  427. 'end_time' => $end_time,
  428. 'rsvp_status' => $rsvp_status));
  429. }
  430. /**
  431. * Returns membership list data associated with an event.
  432. *
  433. * @param int $eid event id
  434. *
  435. * @return array An assoc array of four membership lists, with keys
  436. * 'attending', 'unsure', 'declined', and 'not_replied'
  437. */
  438. public function &events_getMembers($eid) {
  439. return $this->call_method('facebook.events.getMembers',
  440. array('eid' => $eid));
  441. }
  442. /**
  443. * RSVPs the current user to this event.
  444. *
  445. * @param int $eid event id
  446. * @param string $rsvp_status 'attending', 'unsure', or 'declined'
  447. *
  448. * @return bool true if successful
  449. */
  450. public function &events_rsvp($eid, $rsvp_status) {
  451. return $this->call_method('facebook.events.rsvp',
  452. array(
  453. 'eid' => $eid,
  454. 'rsvp_status' => $rsvp_status));
  455. }
  456. /**
  457. * Cancels an event. Only works for events where application is the admin.
  458. *
  459. * @param int $eid event id
  460. * @param string $cancel_message (Optional) message to send to members of
  461. * the event about why it is cancelled
  462. *
  463. * @return bool true if successful
  464. */
  465. public function &events_cancel($eid, $cancel_message='') {
  466. return $this->call_method('facebook.events.cancel',
  467. array('eid' => $eid,
  468. 'cancel_message' => $cancel_message));
  469. }
  470. /**
  471. * Creates an event on behalf of the user is there is a session, otherwise on
  472. * behalf of app. Successful creation guarantees app will be admin.
  473. *
  474. * @param assoc array $event_info json encoded event information
  475. *
  476. * @return int event id
  477. */
  478. public function &events_create($event_info) {
  479. return $this->call_method('facebook.events.create',
  480. array('event_info' => $event_info));
  481. }
  482. /**
  483. * Edits an existing event. Only works for events where application is admin.
  484. *
  485. * @param int $eid event id
  486. * @param assoc array $event_info json encoded event information
  487. *
  488. * @return bool true if successful
  489. */
  490. public function &events_edit($eid, $event_info) {
  491. return $this->call_method('facebook.events.edit',
  492. array('eid' => $eid,
  493. 'event_info' => $event_info));
  494. }
  495. /**
  496. * Fetches and re-caches the image stored at the given URL, for use in images
  497. * published to non-canvas pages via the API (for example, to user profiles
  498. * via profile.setFBML, or to News Feed via feed.publishUserAction).
  499. *
  500. * @param string $url The absolute URL from which to refresh the image.
  501. *
  502. * @return bool true on success
  503. */
  504. public function &fbml_refreshImgSrc($url) {
  505. return $this->call_method('facebook.fbml.refreshImgSrc',
  506. array('url' => $url));
  507. }
  508. /**
  509. * Fetches and re-caches the content stored at the given URL, for use in an
  510. * fb:ref FBML tag.
  511. *
  512. * @param string $url The absolute URL from which to fetch content. This URL
  513. * should be used in a fb:ref FBML tag.
  514. *
  515. * @return bool true on success
  516. */
  517. public function &fbml_refreshRefUrl($url) {
  518. return $this->call_method('facebook.fbml.refreshRefUrl',
  519. array('url' => $url));
  520. }
  521. /**
  522. * Lets you insert text strings in their native language into the Facebook
  523. * Translations database so they can be translated.
  524. *
  525. * @param array $native_strings An array of maps, where each map has a 'text'
  526. * field and a 'description' field.
  527. *
  528. * @return int Number of strings uploaded.
  529. */
  530. public function &fbml_uploadNativeStrings($native_strings) {
  531. return $this->call_method('facebook.fbml.uploadNativeStrings',
  532. array('native_strings' => json_encode($native_strings)));
  533. }
  534. /**
  535. * Associates a given "handle" with FBML markup so that the handle can be
  536. * used within the fb:ref FBML tag. A handle is unique within an application
  537. * and allows an application to publish identical FBML to many user profiles
  538. * and do subsequent updates without having to republish FBML on behalf of
  539. * each user.
  540. *
  541. * @param string $handle The handle to associate with the given FBML.
  542. * @param string $fbml The FBML to associate with the given handle.
  543. *
  544. * @return bool true on success
  545. */
  546. public function &fbml_setRefHandle($handle, $fbml) {
  547. return $this->call_method('facebook.fbml.setRefHandle',
  548. array('handle' => $handle, 'fbml' => $fbml));
  549. }
  550. /**
  551. * Register custom tags for the application. Custom tags can be used
  552. * to extend the set of tags available to applications in FBML
  553. * markup.
  554. *
  555. * Before you call this function,
  556. * make sure you read the full documentation at
  557. *
  558. * http://wiki.developers.facebook.com/index.php/Fbml.RegisterCustomTags
  559. *
  560. * IMPORTANT: This function overwrites the values of
  561. * existing tags if the names match. Use this function with care because
  562. * it may break the FBML of any application that is using the
  563. * existing version of the tags.
  564. *
  565. * @param mixed $tags an array of tag objects (the full description is on the
  566. * wiki page)
  567. *
  568. * @return int the number of tags that were registered
  569. */
  570. public function &fbml_registerCustomTags($tags) {
  571. $tags = json_encode($tags);
  572. return $this->call_method('facebook.fbml.registerCustomTags',
  573. array('tags' => $tags));
  574. }
  575. /**
  576. * Get the custom tags for an application. If $app_id
  577. * is not specified, the calling app's tags are returned.
  578. * If $app_id is different from the id of the calling app,
  579. * only the app's public tags are returned.
  580. * The return value is an array of the same type as
  581. * the $tags parameter of fbml_registerCustomTags().
  582. *
  583. * @param int $app_id the application's id (optional)
  584. *
  585. * @return mixed an array containing the custom tag objects
  586. */
  587. public function &fbml_getCustomTags($app_id = null) {
  588. return $this->call_method('facebook.fbml.getCustomTags',
  589. array('app_id' => $app_id));
  590. }
  591. /**
  592. * Delete custom tags the application has registered. If
  593. * $tag_names is null, all the application's custom tags will be
  594. * deleted.
  595. *
  596. * IMPORTANT: If your application has registered public tags
  597. * that other applications may be using, don't delete those tags!
  598. * Doing so can break the FBML ofapplications that are using them.
  599. *
  600. * @param array $tag_names the names of the tags to delete (optinal)
  601. * @return bool true on success
  602. */
  603. public function &fbml_deleteCustomTags($tag_names = null) {
  604. return $this->call_method('facebook.fbml.deleteCustomTags',
  605. array('tag_names' => json_encode($tag_names)));
  606. }
  607. /**
  608. * This method is deprecated for calls made on behalf of users. This method
  609. * works only for publishing stories on a Facebook Page that has installed
  610. * your application. To publish stories to a user's profile, use
  611. * feed.publishUserAction instead.
  612. *
  613. * For more details on this call, please visit the wiki page:
  614. *
  615. * http://wiki.developers.facebook.com/index.php/Feed.publishTemplatizedAction
  616. */
  617. public function &feed_publishTemplatizedAction($title_template,
  618. $title_data,
  619. $body_template,
  620. $body_data,
  621. $body_general,
  622. $image_1=null,
  623. $image_1_link=null,
  624. $image_2=null,
  625. $image_2_link=null,
  626. $image_3=null,
  627. $image_3_link=null,
  628. $image_4=null,
  629. $image_4_link=null,
  630. $target_ids='',
  631. $page_actor_id=null) {
  632. return $this->call_method('facebook.feed.publishTemplatizedAction',
  633. array('title_template' => $title_template,
  634. 'title_data' => $title_data,
  635. 'body_template' => $body_template,
  636. 'body_data' => $body_data,
  637. 'body_general' => $body_general,
  638. 'image_1' => $image_1,
  639. 'image_1_link' => $image_1_link,
  640. 'image_2' => $image_2,
  641. 'image_2_link' => $image_2_link,
  642. 'image_3' => $image_3,
  643. 'image_3_link' => $image_3_link,
  644. 'image_4' => $image_4,
  645. 'image_4_link' => $image_4_link,
  646. 'target_ids' => $target_ids,
  647. 'page_actor_id' => $page_actor_id));
  648. }
  649. /**
  650. * Registers a template bundle. Template bundles are somewhat involved, so
  651. * it's recommended you check out the wiki for more details:
  652. *
  653. * http://wiki.developers.facebook.com/index.php/Feed.registerTemplateBundle
  654. *
  655. * @return string A template bundle id
  656. */
  657. public function &feed_registerTemplateBundle($one_line_story_templates,
  658. $short_story_templates = array(),
  659. $full_story_template = null,
  660. $action_links = array()) {
  661. $one_line_story_templates = json_encode($one_line_story_templates);
  662. if (!empty($short_story_templates)) {
  663. $short_story_templates = json_encode($short_story_templates);
  664. }
  665. if (isset($full_story_template)) {
  666. $full_story_template = json_encode($full_story_template);
  667. }
  668. if (isset($action_links)) {
  669. $action_links = json_encode($action_links);
  670. }
  671. return $this->call_method('facebook.feed.registerTemplateBundle',
  672. array('one_line_story_templates' => $one_line_story_templates,
  673. 'short_story_templates' => $short_story_templates,
  674. 'full_story_template' => $full_story_template,
  675. 'action_links' => $action_links));
  676. }
  677. /**
  678. * Retrieves the full list of active template bundles registered by the
  679. * requesting application.
  680. *
  681. * @return array An array of template bundles
  682. */
  683. public function &feed_getRegisteredTemplateBundles() {
  684. return $this->call_method('facebook.feed.getRegisteredTemplateBundles',
  685. array());
  686. }
  687. /**
  688. * Retrieves information about a specified template bundle previously
  689. * registered by the requesting application.
  690. *
  691. * @param string $template_bundle_id The template bundle id
  692. *
  693. * @return array Template bundle
  694. */
  695. public function &feed_getRegisteredTemplateBundleByID($template_bundle_id) {
  696. return $this->call_method('facebook.feed.getRegisteredTemplateBundleByID',
  697. array('template_bundle_id' => $template_bundle_id));
  698. }
  699. /**
  700. * Deactivates a previously registered template bundle.
  701. *
  702. * @param string $template_bundle_id The template bundle id
  703. *
  704. * @return bool true on success
  705. */
  706. public function &feed_deactivateTemplateBundleByID($template_bundle_id) {
  707. return $this->call_method('facebook.feed.deactivateTemplateBundleByID',
  708. array('template_bundle_id' => $template_bundle_id));
  709. }
  710. const STORY_SIZE_ONE_LINE = 1;
  711. const STORY_SIZE_SHORT = 2;
  712. const STORY_SIZE_FULL = 4;
  713. /**
  714. * Publishes a story on behalf of the user owning the session, using the
  715. * specified template bundle. This method requires an active session key in
  716. * order to be called.
  717. *
  718. * The parameters to this method ($templata_data in particular) are somewhat
  719. * involved. It's recommended you visit the wiki for details:
  720. *
  721. * http://wiki.developers.facebook.com/index.php/Feed.publishUserAction
  722. *
  723. * @param int $template_bundle_id A template bundle id previously registered
  724. * @param array $template_data See wiki article for syntax
  725. * @param array $target_ids (Optional) An array of friend uids of the
  726. * user who shared in this action.
  727. * @param string $body_general (Optional) Additional markup that extends
  728. * the body of a short story.
  729. * @param int $story_size (Optional) A story size (see above)
  730. * @param string $user_message (Optional) A user message for a short
  731. * story.
  732. *
  733. * @return bool true on success
  734. */
  735. public function &feed_publishUserAction(
  736. $template_bundle_id, $template_data, $target_ids='', $body_general='',
  737. $story_size=FacebookRestClient::STORY_SIZE_ONE_LINE,
  738. $user_message='') {
  739. if (is_array($template_data)) {
  740. $template_data = json_encode($template_data);
  741. } // allow client to either pass in JSON or an assoc that we JSON for them
  742. if (is_array($target_ids)) {
  743. $target_ids = json_encode($target_ids);
  744. $target_ids = trim($target_ids, "[]"); // we don't want square brackets
  745. }
  746. return $this->call_method('facebook.feed.publishUserAction',
  747. array('template_bundle_id' => $template_bundle_id,
  748. 'template_data' => $template_data,
  749. 'target_ids' => $target_ids,
  750. 'body_general' => $body_general,
  751. 'story_size' => $story_size,
  752. 'user_message' => $user_message));
  753. }
  754. /**
  755. * Publish a post to the user's stream.
  756. *
  757. * @param $message the user's message
  758. * @param $attachment the post's attachment (optional)
  759. * @param $action links the post's action links (optional)
  760. * @param $target_id the user on whose wall the post will be posted
  761. * (optional)
  762. * @param $uid the actor (defaults to session user)
  763. * @return string the post id
  764. */
  765. public function stream_publish(
  766. $message, $attachment = null, $action_links = null, $target_id = null,
  767. $uid = null) {
  768. return $this->call_method(
  769. 'facebook.stream.publish',
  770. array('message' => $message,
  771. 'attachment' => $attachment,
  772. 'action_links' => $action_links,
  773. 'target_id' => $target_id,
  774. 'uid' => $this->get_uid($uid)));
  775. }
  776. /**
  777. * Remove a post from the user's stream.
  778. * Currently, you may only remove stories you application created.
  779. *
  780. * @param $post_id the post id
  781. * @param $uid the actor (defaults to session user)
  782. * @return bool
  783. */
  784. public function stream_remove($post_id, $uid = null) {
  785. return $this->call_method(
  786. 'facebook.stream.remove',
  787. array('post_id' => $post_id,
  788. 'uid' => $this->get_uid($uid)));
  789. }
  790. /**
  791. * Add a comment to a stream post
  792. *
  793. * @param $post_id the post id
  794. * @param $comment the comment text
  795. * @param $uid the actor (defaults to session user)
  796. * @return string the id of the created comment
  797. */
  798. public function stream_addComment($post_id, $comment, $uid = null) {
  799. return $this->call_method(
  800. 'facebook.stream.addComment',
  801. array('post_id' => $post_id,
  802. 'comment' => $comment,
  803. 'uid' => $this->get_uid($uid)));
  804. }
  805. /**
  806. * Remove a comment from a stream post
  807. *
  808. * @param $comment_id the comment id
  809. * @param $uid the actor (defaults to session user)
  810. * @return bool
  811. */
  812. public function stream_removeComment($comment_id, $uid = null) {
  813. return $this->call_method(
  814. 'facebook.stream.removeComment',
  815. array('comment_id' => $comment_id,
  816. 'uid' => $this->get_uid($uid)));
  817. }
  818. /**
  819. * Add a like to a stream post
  820. *
  821. * @param $post_id the post id
  822. * @param $uid the actor (defaults to session user)
  823. * @return bool
  824. */
  825. public function stream_addLike($post_id, $uid = null) {
  826. return $this->call_method(
  827. 'facebook.stream.addLike',
  828. array('post_id' => $post_id,
  829. 'uid' => $this->get_uid($uid)));
  830. }
  831. /**
  832. * Remove a like from a stream post
  833. *
  834. * @param $post_id the post id
  835. * @param $uid the actor (defaults to session user)
  836. * @return bool
  837. */
  838. public function stream_removeLike($post_id, $uid = null) {
  839. return $this->call_method(
  840. 'facebook.stream.removeLike',
  841. array('post_id' => $post_id,
  842. 'uid' => $this->get_uid($uid)));
  843. }
  844. /**
  845. * For the current user, retrieves stories generated by the user's friends
  846. * while using this application. This can be used to easily create a
  847. * "News Feed" like experience.
  848. *
  849. * @return array An array of feed story objects.
  850. */
  851. public function &feed_getAppFriendStories() {
  852. return $this->call_method('facebook.feed.getAppFriendStories');
  853. }
  854. /**
  855. * Makes an FQL query. This is a generalized way of accessing all the data
  856. * in the API, as an alternative to most of the other method calls. More
  857. * info at http://developers.facebook.com/documentation.php?v=1.0&doc=fql
  858. *
  859. * @param string $query the query to evaluate
  860. *
  861. * @return array generalized array representing the results
  862. */
  863. public function &fql_query($query) {
  864. return $this->call_method('facebook.fql.query',
  865. array('query' => $query));
  866. }
  867. /**
  868. * Returns whether or not pairs of users are friends.
  869. * Note that the Facebook friend relationship is symmetric.
  870. *
  871. * @param array/string $uids1 list of ids (id_1, id_2,...)
  872. * of some length X (csv is deprecated)
  873. * @param array/string $uids2 list of ids (id_A, id_B,...)
  874. * of SAME length X (csv is deprecated)
  875. *
  876. * @return array An array with uid1, uid2, and bool if friends, e.g.:
  877. * array(0 => array('uid1' => id_1, 'uid2' => id_A, 'are_friends' => 1),
  878. * 1 => array('uid1' => id_2, 'uid2' => id_B, 'are_friends' => 0)
  879. * ...)
  880. * @error
  881. * API_EC_PARAM_USER_ID_LIST
  882. */
  883. public function &friends_areFriends($uids1, $uids2) {
  884. return $this->call_method('facebook.friends.areFriends',
  885. array('uids1' => $uids1,
  886. 'uids2' => $uids2));
  887. }
  888. /**
  889. * Returns the friends of the current session user.
  890. *
  891. * @param int $flid (Optional) Only return friends on this friend list.
  892. * @param int $uid (Optional) Return friends for this user.
  893. *
  894. * @return array An array of friends
  895. */
  896. public function &friends_get($flid=null, $uid = null) {
  897. if (isset($this->friends_list)) {
  898. return $this->friends_list;
  899. }
  900. $params = array();
  901. if (!$uid && isset($this->canvas_user)) {
  902. $uid = $this->canvas_user;
  903. }
  904. if ($uid) {
  905. $params['uid'] = $uid;
  906. }
  907. if ($flid) {
  908. $params['flid'] = $flid;
  909. }
  910. return $this->call_method('facebook.friends.get', $params);
  911. }
  912. /**
  913. * Returns the set of friend lists for the current session user.
  914. *
  915. * @return array An array of friend list objects
  916. */
  917. public function &friends_getLists() {
  918. return $this->call_method('facebook.friends.getLists');
  919. }
  920. /**
  921. * Returns the friends of the session user, who are also users
  922. * of the calling application.
  923. *
  924. * @return array An array of friends also using the app
  925. */
  926. public function &friends_getAppUsers() {
  927. return $this->call_method('facebook.friends.getAppUsers');
  928. }
  929. /**
  930. * Returns groups according to the filters specified.
  931. *
  932. * @param int $uid (Optional) User associated with groups. A null
  933. * parameter will default to the session user.
  934. * @param array/string $gids (Optional) Array of group ids to query. A null
  935. * parameter will get all groups for the user.
  936. * (csv is deprecated)
  937. *
  938. * @return array An array of group objects
  939. */
  940. public function &groups_get($uid, $gids) {
  941. return $this->call_method('facebook.groups.get',
  942. array('uid' => $uid,
  943. 'gids' => $gids));
  944. }
  945. /**
  946. * Returns the membership list of a group.
  947. *
  948. * @param int $gid Group id
  949. *
  950. * @return array An array with four membership lists, with keys 'members',
  951. * 'admins', 'officers', and 'not_replied'
  952. */
  953. public function &groups_getMembers($gid) {
  954. return $this->call_method('facebook.groups.getMembers',
  955. array('gid' => $gid));
  956. }
  957. /**
  958. * Returns cookies according to the filters specified.
  959. *
  960. * @param int $uid User for which the cookies are needed.
  961. * @param string $name (Optional) A null parameter will get all cookies
  962. * for the user.
  963. *
  964. * @return array Cookies! Nom nom nom nom nom.
  965. */
  966. public function data_getCookies($uid, $name) {
  967. return $this->call_method('facebook.data.getCookies',
  968. array('uid' => $uid,
  969. 'name' => $name));
  970. }
  971. /**
  972. * Sets cookies according to the params specified.
  973. *
  974. * @param int $uid User for which the cookies are needed.
  975. * @param string $name Name of the cookie
  976. * @param string $value (Optional) if expires specified and is in the past
  977. * @param int $expires (Optional) Expiry time
  978. * @param string $path (Optional) Url path to associate with (default is /)
  979. *
  980. * @return bool true on success
  981. */
  982. public function data_setCookie($uid, $name, $value, $expires, $path) {
  983. return $this->call_method('facebook.data.setCookie',
  984. array('uid' => $uid,
  985. 'name' => $name,
  986. 'value' => $value,
  987. 'expires' => $expires,
  988. 'path' => $path));
  989. }
  990. /**
  991. * Retrieves links posted by the given user.
  992. *
  993. * @param int $uid The user whose links you wish to retrieve
  994. * @param int $limit The maximimum number of links to retrieve
  995. * @param array $link_ids (Optional) Array of specific link
  996. * IDs to retrieve by this user
  997. *
  998. * @return array An array of links.
  999. */
  1000. public function &links_get($uid, $limit, $link_ids = null) {
  1001. return $this->call_method('links.get',
  1002. array('uid' => $uid,
  1003. 'limit' => $limit,
  1004. 'link_ids' => $link_ids));
  1005. }
  1006. /**
  1007. * Posts a link on Facebook.
  1008. *
  1009. * @param string $url URL/link you wish to post
  1010. * @param string $comment (Optional) A comment about this link
  1011. * @param int $uid (Optional) User ID that is posting this link;
  1012. * defaults to current session user
  1013. *
  1014. * @return bool
  1015. */
  1016. public function &links_post($url, $comment='', $uid = null) {
  1017. return $this->call_method('links.post',
  1018. array('uid' => $uid,
  1019. 'url' => $url,
  1020. 'comment' => $comment));
  1021. }
  1022. /**
  1023. * Permissions API
  1024. */
  1025. /**
  1026. * Checks API-access granted by self to the specified application.
  1027. *
  1028. * @param string $permissions_apikey Other application key
  1029. *
  1030. * @return array API methods/namespaces which are allowed access
  1031. */
  1032. public function permissions_checkGrantedApiAccess($permissions_apikey) {
  1033. return $this->call_method('facebook.permissions.checkGrantedApiAccess',
  1034. array('permissions_apikey' => $permissions_apikey));
  1035. }
  1036. /**
  1037. * Checks API-access granted to self by the specified application.
  1038. *
  1039. * @param string $permissions_apikey Other application key
  1040. *
  1041. * @return array API methods/namespaces which are allowed access
  1042. */
  1043. public function permissions_checkAvailableApiAccess($permissions_apikey) {
  1044. return $this->call_method('facebook.permissions.checkAvailableApiAccess',
  1045. array('permissions_apikey' => $permissions_apikey));
  1046. }
  1047. /**
  1048. * Grant API-access to the specified methods/namespaces to the specified
  1049. * application.
  1050. *
  1051. * @param string $permissions_apikey Other application key
  1052. * @param array(string) $method_arr (Optional) API methods/namespaces
  1053. * allowed
  1054. *
  1055. * @return array API methods/namespaces which are allowed access
  1056. */
  1057. public function permissions_grantApiAccess($permissions_apikey, $method_arr) {
  1058. return $this->call_method('facebook.permissions.grantApiAccess',
  1059. array('permissions_apikey' => $permissions_apikey,
  1060. 'method_arr' => $method_arr));
  1061. }
  1062. /**
  1063. * Revoke API-access granted to the specified application.
  1064. *
  1065. * @param string $permissions_apikey Other application key
  1066. *
  1067. * @return bool true on success
  1068. */
  1069. public function permissions_revokeApiAccess($permissions_apikey) {
  1070. return $this->call_method('facebook.permissions.revokeApiAccess',
  1071. array('permissions_apikey' => $permissions_apikey));
  1072. }
  1073. /**
  1074. * Creates a note with the specified title and content.
  1075. *
  1076. * @param string $title Title of the note.
  1077. * @param string $content Content of the note.
  1078. * @param int $uid (Optional) The user for whom you are creating a
  1079. * note; defaults to current session user
  1080. *
  1081. * @return int The ID of the note that was just created.
  1082. */
  1083. public function &notes_create($title, $content, $uid = null) {
  1084. return $this->call_method('notes.create',
  1085. array('uid' => $uid,
  1086. 'title' => $title,
  1087. 'content' => $content));
  1088. }
  1089. /**
  1090. * Deletes the specified note.
  1091. *
  1092. * @param int $note_id ID of the note you wish to delete
  1093. * @param int $uid (Optional) Owner of the note you wish to delete;
  1094. * defaults to current session user
  1095. *
  1096. * @return bool
  1097. */
  1098. public function &notes_delete($note_id, $uid = null) {
  1099. return $this->call_method('notes.delete',
  1100. array('uid' => $uid,
  1101. 'note_id' => $note_id));
  1102. }
  1103. /**
  1104. * Edits a note, replacing its title and contents with the title
  1105. * and contents specified.
  1106. *
  1107. * @param int $note_id ID of the note you wish to edit
  1108. * @param string $title Replacement title for the note
  1109. * @param string $content Replacement content for the note
  1110. * @param int $uid (Optional) Owner of the note you wish to edit;
  1111. * defaults to current session user
  1112. *
  1113. * @return bool
  1114. */
  1115. public function &notes_edit($note_id, $title, $content, $uid = null) {
  1116. return $this->call_method('notes.edit',
  1117. array('uid' => $uid,
  1118. 'note_id' => $note_id,
  1119. 'title' => $title,
  1120. 'content' => $content));
  1121. }
  1122. /**
  1123. * Retrieves all notes by a user. If note_ids are specified,
  1124. * retrieves only those specific notes by that user.
  1125. *
  1126. * @param int $uid User whose notes you wish to retrieve
  1127. * @param array $note_ids (Optional) List of specific note
  1128. * IDs by this user to retrieve
  1129. *
  1130. * @return array A list of all of the given user's notes, or an empty list
  1131. * if the viewer lacks permissions or if there are no visible
  1132. * notes.
  1133. */
  1134. public function &notes_get($uid, $note_ids = null) {
  1135. return $this->call_method('notes.get',
  1136. array('uid' => $uid,
  1137. 'note_ids' => $note_ids));
  1138. }
  1139. /**
  1140. * Returns the outstanding notifications for the session user.
  1141. *
  1142. * @return array An assoc array of notification count objects for
  1143. * 'messages', 'pokes' and 'shares', a uid list of
  1144. * 'friend_requests', a gid list of 'group_invites',
  1145. * and an eid list of 'event_invites'
  1146. */
  1147. public function &notifications_get() {
  1148. return $this->call_method('facebook.notifications.get');
  1149. }
  1150. /**
  1151. * Sends a notification to the specified users.
  1152. *
  1153. * @return A comma separated list of successful recipients
  1154. * @error
  1155. * API_EC_PARAM_USER_ID_LIST
  1156. */
  1157. public function &notifications_send($to_ids, $notification, $type) {
  1158. return $this->call_method('facebook.notifications.send',
  1159. array('to_ids' => $to_ids,
  1160. 'notification' => $notification,
  1161. 'type' => $type));
  1162. }
  1163. /**
  1164. * Sends an email to the specified user of the application.
  1165. *
  1166. * @param array/string $recipients array of ids of the recipients (csv is deprecated)
  1167. * @param string $subject subject of the email
  1168. * @param string $text (plain text) body of the email
  1169. * @param string $fbml fbml markup for an html version of the email
  1170. *
  1171. * @return string A comma separated list of successful recipients
  1172. * @error
  1173. * API_EC_PARAM_USER_ID_LIST
  1174. */
  1175. public function &notifications_sendEmail($recipients,
  1176. $subject,
  1177. $text,
  1178. $fbml) {
  1179. return $this->call_method('facebook.notifications.sendEmail',
  1180. array('recipients' => $recipients,
  1181. 'subject' => $subject,
  1182. 'text' => $text,
  1183. 'fbml' => $fbml));
  1184. }
  1185. /**
  1186. * Returns the requested info fields for the requested set of pages.
  1187. *
  1188. * @param array/string $page_ids an array of page ids (csv is deprecated)
  1189. * @param array/string $fields an array of strings describing the
  1190. * info fields desired (csv is deprecated)
  1191. * @param int $uid (Optional) limit results to pages of which this
  1192. * user is a fan.
  1193. * @param string type limits results to a particular type of page.
  1194. *
  1195. * @return array An array of pages
  1196. */
  1197. public function &pages_getInfo($page_ids, $fields, $uid, $type) {
  1198. return $this->call_method('facebook.pages.getInfo',
  1199. array('page_ids' => $page_ids,
  1200. 'fields' => $fields,
  1201. 'uid' => $uid,
  1202. 'type' => $type));
  1203. }
  1204. /**
  1205. * Returns true if the given user is an admin for the passed page.
  1206. *
  1207. * @param int $page_id target page id
  1208. * @param int $uid (Optional) user id (defaults to the logged-in user)
  1209. *
  1210. * @return bool true on success
  1211. */
  1212. public function &pages_isAdmin($page_id, $uid = null) {
  1213. return $this->call_method('facebook.pages.isAdmin',
  1214. array('page_id' => $page_id,
  1215. 'uid' => $uid));
  1216. }
  1217. /**
  1218. * Returns whether or not the given page has added the application.
  1219. *
  1220. * @param int $page_id target page id
  1221. *
  1222. * @return bool true on success
  1223. */
  1224. public function &pages_isAppAdded($page_id) {
  1225. return $this->call_method('facebook.pages.isAppAdded',
  1226. array('page_id' => $page_id));
  1227. }
  1228. /**
  1229. * Returns true if logged in user is a fan for the passed page.
  1230. *
  1231. * @param int $page_id target page id
  1232. * @param int $uid user to compare. If empty, the logged in user.
  1233. *
  1234. * @return bool true on success
  1235. */
  1236. public function &pages_isFan($page_id, $uid = null) {
  1237. return $this->call_method('facebook.pages.isFan',
  1238. array('page_id' => $page_id,
  1239. 'uid' => $uid));
  1240. }
  1241. /**
  1242. * Adds a tag with the given information to a photo. See the wiki for details:
  1243. *
  1244. * http://wiki.developers.facebook.com/index.php/Photos.addTag
  1245. *
  1246. * @param int $pid The ID of the photo to be tagged
  1247. * @param int $tag_uid The ID of the user being tagged. You must specify
  1248. * either the $tag_uid or the $tag_text parameter
  1249. * (unless $tags is specified).
  1250. * @param string $tag_text Some text identifying the person being tagged.
  1251. * You must specify either the $tag_uid or $tag_text
  1252. * parameter (unless $tags is specified).
  1253. * @param float $x The horizontal position of the tag, as a
  1254. * percentage from 0 to 100, from the left of the
  1255. * photo.
  1256. * @param float $y The vertical position of the tag, as a percentage
  1257. * from 0 to 100, from the top of the photo.
  1258. * @param array $tags (Optional) An array of maps, where each map
  1259. * can contain the tag_uid, tag_text, x, and y
  1260. * parameters defined above. If specified, the
  1261. * individual arguments are ignored.
  1262. * @param int $owner_uid (Optional) The user ID of the user whose photo
  1263. * you are tagging. If this parameter is not
  1264. * specified, then it defaults to the session user.
  1265. *
  1266. * @return bool true on success
  1267. */
  1268. public function &photos_addTag($pid,
  1269. $tag_uid,
  1270. $tag_text,
  1271. $x,
  1272. $y,
  1273. $tags,
  1274. $owner_uid=0) {
  1275. return $this->call_method('facebook.photos.addTag',
  1276. array('pid' => $pid,
  1277. 'tag_uid' => $tag_uid,
  1278. 'tag_text' => $tag_text,
  1279. 'x' => $x,
  1280. 'y' => $y,
  1281. 'tags' => (is_array($tags)) ? json_encode($tags) : null,
  1282. 'owner_uid' => $this->get_uid($owner_uid)));
  1283. }
  1284. /**
  1285. * Creates and returns a new album owned by the specified user or the current
  1286. * session user.
  1287. *
  1288. * @param string $name The name of the album.
  1289. * @param string $description (Optional) A description of the album.
  1290. * @param string $location (Optional) A description of the location.
  1291. * @param string $visible (Optional) A privacy setting for the album.
  1292. * One of 'friends', 'friends-of-friends',
  1293. * 'networks', or 'everyone'. Default 'everyone'.
  1294. * @param int $uid (Optional) User id for creating the album; if
  1295. * not specified, the session user is used.
  1296. *
  1297. * @return array An album object
  1298. */
  1299. public function &photos_createAlbum($name,
  1300. $description='',
  1301. $location='',
  1302. $visible='',
  1303. $uid=0) {
  1304. return $this->call_method('facebook.photos.createAlbum',
  1305. array('name' => $name,
  1306. 'description' => $description,
  1307. 'location' => $location,
  1308. 'visible' => $visible,
  1309. 'uid' => $this->get_uid($uid)));
  1310. }
  1311. /**
  1312. * Returns photos according to the filters specified.
  1313. *
  1314. * @param int $subj_id (Optional) Filter by uid of user tagged in the photos.
  1315. * @param int $aid (Optional) Filter by an album, as returned by
  1316. * photos_getAlbums.
  1317. * @param array/string $pids (Optional) Restrict to an array of pids
  1318. * (csv is deprecated)
  1319. *
  1320. * Note that at least one of these parameters needs to be specified, or an
  1321. * error is returned.
  1322. *
  1323. * @return array An array of photo objects.
  1324. */
  1325. public function &photos_get($subj_id, $aid, $pids) {
  1326. return $this->call_method('facebook.photos.get',
  1327. array('subj_id' => $subj_id, 'aid' => $aid, 'pids' => $pids));
  1328. }
  1329. /**
  1330. * Returns the albums created by the given user.
  1331. *
  1332. * @param int $uid (Optional) The uid of the user whose albums you want.
  1333. * A null will return the albums of the session user.
  1334. * @param string $aids (Optional) An array of aids to restrict
  1335. * the query. (csv is deprecated)
  1336. *
  1337. * Note that at least one of the (uid, aids) parameters must be specified.
  1338. *
  1339. * @returns an array of album objects.
  1340. */
  1341. public function &photos_getAlbums($uid, $aids) {
  1342. return $this->call_method('facebook.photos.getAlbums',
  1343. array('uid' => $uid,
  1344. 'aids' => $aids));
  1345. }
  1346. /**
  1347. * Returns the tags on all photos specified.
  1348. *
  1349. * @param string $pids A list of pids to query
  1350. *
  1351. * @return array An array of photo tag objects, which include pid,
  1352. * subject uid, and two floating-point numbers (xcoord, ycoord)
  1353. * for tag pixel location.
  1354. */
  1355. public function &photos_getTags($pids) {
  1356. return $this->call_method('facebook.photos.getTags',
  1357. array('pids' => $pids));
  1358. }
  1359. /**
  1360. * Uploads a photo.
  1361. *
  1362. * @param string $file The location of the photo on the local filesystem.
  1363. * @param int $aid (Optional) The album into which to upload the
  1364. * photo.
  1365. * @param string $caption (Optional) A caption for the photo.
  1366. * @param int uid (Optional) The user ID of the user whose photo you
  1367. * are uploading
  1368. *
  1369. * @return array An array of user objects
  1370. */
  1371. public function photos_upload($file, $aid=null, $caption=null, $uid=null) {
  1372. return $this->call_upload_method('facebook.photos.upload',
  1373. array('aid' => $aid,
  1374. 'caption' => $caption,
  1375. 'uid' => $uid),
  1376. $file);
  1377. }
  1378. /**
  1379. * Uploads a video.
  1380. *
  1381. * @param string $file The location of the video on the local filesystem.
  1382. * @param string $title (Optional) A title for the video. Titles over 65 characters in length will be truncated.
  1383. * @param string $description (Optional) A description for the video.
  1384. *
  1385. * @return array An array with the video's ID, title, description, and a link to view it on Facebook.
  1386. */
  1387. public function video_upload($file, $title=null, $description=null) {
  1388. return $this->call_upload_method('facebook.video.upload',
  1389. array('title' => $title,
  1390. 'description' => $description),
  1391. $file,
  1392. Facebook::get_facebook_url('api-video') . '/restserver.php');
  1393. }
  1394. /**
  1395. * Returns an array with the video limitations imposed on the current session's
  1396. * associated user. Maximum length is measured in seconds; maximum size is
  1397. * measured in bytes.
  1398. *
  1399. * @return array Array with "length" and "size" keys
  1400. */
  1401. public function &video_getUploadLimits() {
  1402. return $this->call_method('facebook.video.getUploadLimits');
  1403. }
  1404. /**
  1405. * Returns the requested info fields for the requested set of users.
  1406. *
  1407. * @param array/string $uids An array of user ids (csv is deprecated)
  1408. * @param array/string $fields An array of info field names desired (csv is deprecated)
  1409. *
  1410. * @return array An array of user objects
  1411. */
  1412. public function &users_getInfo($uids, $fields) {
  1413. return $this->call_method('facebook.users.getInfo',
  1414. array('uids' => $uids,
  1415. 'fields' => $fields));
  1416. }
  1417. /**
  1418. * Returns the requested info fields for the requested set of users. A
  1419. * session key must not be specified. Only data about users that have
  1420. * authorized your application will be returned.
  1421. *
  1422. * Check the wiki for fields that can be queried through this API call.
  1423. * Data returned from here should not be used for rendering to application
  1424. * users, use users.getInfo instead, so that proper privacy rules will be
  1425. * applied.
  1426. *
  1427. * @param array/string $uids An array of user ids (csv is deprecated)
  1428. * @param array/string $fields An array of info field names desired (csv is deprecated)
  1429. *
  1430. * @return array An array of user objects
  1431. */
  1432. public function &users_getStandardInfo($uids, $fields) {
  1433. return $this->call_method('facebook.users.getStandardInfo',
  1434. array('uids' => $uids,
  1435. 'fields' => $fields));
  1436. }
  1437. /**
  1438. * Returns the user corresponding to the current session object.
  1439. *
  1440. * @return integer User id
  1441. */
  1442. public function &users_getLoggedInUser() {
  1443. return $this->call_method('facebook.users.getLoggedInUser');
  1444. }
  1445. /**
  1446. * Returns 1 if the user has the specified permission, 0 otherwise.
  1447. * http://wiki.developers.facebook.com/index.php/Users.hasAppPermission
  1448. *
  1449. * @return integer 1 or 0
  1450. */
  1451. public function &users_hasAppPermission($ext_perm, $uid=null) {
  1452. return $this->call_method('facebook.users.hasAppPermission',
  1453. array('ext_perm' => $ext_perm, 'uid' => $uid));
  1454. }
  1455. /**
  1456. * Returns whether or not the user corresponding to the current
  1457. * session object has the give the app basic authorization.
  1458. *
  1459. * @return boolean true if the user has authorized the app
  1460. */
  1461. public function &users_isAppUser($uid=null) {
  1462. if ($uid === null && isset($this->is_user)) {
  1463. return $this->is_user;
  1464. }
  1465. return $this->call_method('facebook.users.isAppUser', array('uid' => $uid));
  1466. }
  1467. /**
  1468. * Returns whether or not the user corresponding to the current
  1469. * session object is verified by Facebook. See the documentation
  1470. * for Users.isVerified for details.
  1471. *
  1472. * @return boolean true if the user is verified
  1473. */
  1474. public function &users_isVerified() {
  1475. return $this->call_method('facebook.users.isVerified');
  1476. }
  1477. /**
  1478. * Sets the users' current status message. Message does NOT contain the
  1479. * word "is" , so make sure to include a verb.
  1480. *
  1481. * Example: setStatus("is loving the API!")
  1482. * will produce the status "Luke is loving the API!"
  1483. *
  1484. * @param string $status text-only message to set
  1485. * @param int $uid user to set for (defaults to the
  1486. * logged-in user)
  1487. * @param bool $clear whether or not to clear the status,
  1488. * instead of setting it
  1489. * @param bool $status_includes_verb if true, the word "is" will *not* be
  1490. * prepended to the status message
  1491. *
  1492. * @return boolean
  1493. */
  1494. public function &users_setStatus($status,
  1495. $uid = null,
  1496. $clear = false,
  1497. $status_includes_verb = true) {
  1498. $args = array(
  1499. 'status' => $status,
  1500. 'uid' => $uid,
  1501. 'clear' => $clear,
  1502. 'status_includes_verb' => $status_includes_verb,
  1503. );
  1504. return $this->call_method('facebook.users.setStatus', $args);
  1505. }
  1506. /**
  1507. * Gets the stream on behalf of a user using a set of users. This
  1508. * call will return the latest $limit queries between $start_time
  1509. * and $end_time.
  1510. *
  1511. * @param int $viewer_id user making the call (def: session)
  1512. * @param array $source_ids users/pages to look at (def: all connections)
  1513. * @param int $start_time start time to look for stories (def: 1 day ago)
  1514. * @param int $end_time end time to look for stories (def: now)
  1515. * @param int $limit number of stories to attempt to fetch (def: 30)
  1516. * @param string $filter_key key returned by stream.getFilters to fetch
  1517. *
  1518. * @return array(
  1519. * 'posts' => array of posts,
  1520. * 'profiles' => array of profile metadata of users/pages in posts
  1521. * 'albums' => array of album metadata in posts
  1522. * )
  1523. */
  1524. public function &stream_get($viewer_id = null,
  1525. $source_ids = null,
  1526. $start_time = 0,
  1527. $end_time = 0,
  1528. $limit = 30,
  1529. $filter_key = '') {
  1530. $args = array(
  1531. 'viewer_id' => $viewer_id,
  1532. 'source_ids' => $source_ids,
  1533. 'start_time' => $start_time,
  1534. 'end_time' => $end_time,
  1535. 'limit' => $limit,
  1536. 'filter_key' => $filter_key);
  1537. return $this->call_method('facebook.stream.get', $args);
  1538. }
  1539. /**
  1540. * Gets the filters (with relevant filter keys for stream.get) for a
  1541. * particular user. These filters are typical things like news feed,
  1542. * friend lists, networks. They can be used to filter the stream
  1543. * without complex queries to determine which ids belong in which groups.
  1544. *
  1545. * @param int $uid user to get filters for
  1546. *
  1547. * @return array of stream filter objects
  1548. */
  1549. public function &stream_getFilters($uid = null) {
  1550. $args = array('uid' => $uid);
  1551. return $this->call_method('facebook.stream.getFilters', $args);
  1552. }
  1553. /**
  1554. * Gets the full comments given a post_id from stream.get or the
  1555. * stream FQL table. Initially, only a set of preview comments are
  1556. * returned because some posts can have many comments.
  1557. *
  1558. * @param string $post_id id of the post to get comments for
  1559. *
  1560. * @return array of comment objects
  1561. */
  1562. public function &stream_getComments($post_id) {
  1563. $args = array('post_id' => $post_id);
  1564. return $this->call_method('facebook.stream.getComments', $args);
  1565. }
  1566. /**
  1567. * Sets the FBML for the profile of the user attached to this session.
  1568. *
  1569. * @param string $markup The FBML that describes the profile
  1570. * presence of this app for the user
  1571. * @param int $uid The user
  1572. * @param string $profile Profile FBML
  1573. * @param string $profile_action Profile action FBML (deprecated)
  1574. * @param string $mobile_profile Mobile profile FBML
  1575. * @param string $profile_main Main Tab profile FBML
  1576. *
  1577. * @return array A list of strings describing any compile errors for the
  1578. * submitted FBML
  1579. */
  1580. function profile_setFBML($markup,
  1581. $uid=null,
  1582. $profile='',
  1583. $profile_action='',
  1584. $mobile_profile='',
  1585. $profile_main='') {
  1586. return $this->call_method('facebook.profile.setFBML',
  1587. array('markup' => $markup,
  1588. 'uid' => $uid,
  1589. 'profile' => $profile,
  1590. 'profile_action' => $profile_action,
  1591. 'mobile_profile' => $mobile_profile,
  1592. 'profile_main' => $profile_main));
  1593. }
  1594. /**
  1595. * Gets the FBML for the profile box that is currently set for a user's
  1596. * profile (your application set the FBML previously by calling the
  1597. * profile.setFBML method).
  1598. *
  1599. * @param int $uid (Optional) User id to lookup; defaults to session.
  1600. * @param int $type (Optional) 1 for original style, 2 for profile_main boxes
  1601. *
  1602. * @return string The FBML
  1603. */
  1604. public function &profile_getFBML($uid=null, $type=null) {
  1605. return $this->call_method('facebook.profile.getFBML',
  1606. array('uid' => $uid,
  1607. 'type' => $type));
  1608. }
  1609. /**
  1610. * Returns the specified user's application info section for the calling
  1611. * application. These info sections have either been set via a previous
  1612. * profile.setInfo call or by the user editing them directly.
  1613. *
  1614. * @param int $uid (Optional) User id to lookup; defaults to session.
  1615. *
  1616. * @return array Info fields for the current user. See wiki for structure:
  1617. *
  1618. * http://wiki.developers.facebook.com/index.php/Profile.getInfo
  1619. *
  1620. */
  1621. public function &profile_getInfo($uid=null) {
  1622. return $this->call_method('facebook.profile.getInfo',
  1623. array('uid' => $uid));
  1624. }
  1625. /**
  1626. * Returns the options associated with the specified info field for an
  1627. * application info section.
  1628. *
  1629. * @param string $field The title of the field
  1630. *
  1631. * @return array An array of info options.
  1632. */
  1633. public function &profile_getInfoOptions($field) {
  1634. return $this->call_method('facebook.profile.getInfoOptions',
  1635. array('field' => $field));
  1636. }
  1637. /**
  1638. * Configures an application info section that the specified user can install
  1639. * on the Info tab of her profile. For details on the structure of an info
  1640. * field, please see:
  1641. *
  1642. * http://wiki.developers.facebook.com/index.php/Profile.setInfo
  1643. *
  1644. * @param string $title Title / header of the info section
  1645. * @param int $type 1 for text-only, 5 for thumbnail views
  1646. * @param array $info_fields An array of info fields. See wiki for details.
  1647. * @param int $uid (Optional)
  1648. *
  1649. * @return bool true on success
  1650. */
  1651. public function &profile_setInfo($title, $type, $info_fields, $uid=null) {
  1652. return $this->call_method('facebook.profile.setInfo',
  1653. array('uid' => $uid,
  1654. 'type' => $type,
  1655. 'title' => $title,
  1656. 'info_fields' => json_encode($info_fields)));
  1657. }
  1658. /**
  1659. * Specifies the objects for a field for an application info section. These
  1660. * options populate the typeahead for a thumbnail.
  1661. *
  1662. * @param string $field The title of the field
  1663. * @param array $options An array of items for a thumbnail, including
  1664. * 'label', 'link', and optionally 'image',
  1665. * 'description' and 'sublabel'
  1666. *
  1667. * @return bool true on success
  1668. */
  1669. public function profile_setInfoOptions($field, $options) {
  1670. return $this->call_method('facebook.profile.setInfoOptions',
  1671. array('field' => $field,
  1672. 'options' => json_encode($options)));
  1673. }
  1674. /**
  1675. * Get all the marketplace categories.
  1676. *
  1677. * @return array A list of category names
  1678. */
  1679. function marketplace_getCategories() {
  1680. return $this->call_method('facebook.marketplace.getCategories',
  1681. array());
  1682. }
  1683. /**
  1684. * Get all the marketplace subcategories for a particular category.
  1685. *
  1686. * @param category The category for which we are pulling subcategories
  1687. *
  1688. * @return array A list of subcategory names
  1689. */
  1690. function marketplace_getSubCategories($category) {
  1691. return $this->call_method('facebook.marketplace.getSubCategories',
  1692. array('category' => $category));
  1693. }
  1694. /**
  1695. * Get listings by either listing_id or user.
  1696. *
  1697. * @param listing_ids An array of listing_ids (optional)
  1698. * @param uids An array of user ids (optional)
  1699. *
  1700. * @return array The data for matched listings
  1701. */
  1702. function marketplace_getListings($listing_ids, $uids) {
  1703. return $this->call_method('facebook.marketplace.getListings',
  1704. array('listing_ids' => $listing_ids, 'uids' => $uids));
  1705. }
  1706. /**
  1707. * Search for Marketplace listings. All arguments are optional, though at
  1708. * least one must be filled out to retrieve results.
  1709. *
  1710. * @param category The category in which to search (optional)
  1711. * @param subcategory The subcategory in which to search (optional)
  1712. * @param query A query string (optional)
  1713. *
  1714. * @return array The data for matched listings
  1715. */
  1716. function marketplace_search($category, $subcategory, $query) {
  1717. return $this->call_method('facebook.marketplace.search',
  1718. array('category' => $category,
  1719. 'subcategory' => $subcategory,
  1720. 'query' => $query));
  1721. }
  1722. /**
  1723. * Remove a listing from Marketplace.
  1724. *
  1725. * @param listing_id The id of the listing to be removed
  1726. * @param status 'SUCCESS', 'NOT_SUCCESS', or 'DEFAULT'
  1727. *
  1728. * @return bool True on success
  1729. */
  1730. function marketplace_removeListing($listing_id,
  1731. $status='DEFAULT',
  1732. $uid=null) {
  1733. return $this->call_method('facebook.marketplace.removeListing',
  1734. array('listing_id' => $listing_id,
  1735. 'status' => $status,
  1736. 'uid' => $uid));
  1737. }
  1738. /**
  1739. * Create/modify a Marketplace listing for the loggedinuser.
  1740. *
  1741. * @param int listing_id The id of a listing to be modified, 0
  1742. * for a new listing.
  1743. * @param show_on_profile bool Should we show this listing on the
  1744. * user's profile
  1745. * @param listing_attrs array An array of the listing data
  1746. *
  1747. * @return int The listing_id (unchanged if modifying an existing listing).
  1748. */
  1749. function marketplace_createListing($listing_id,
  1750. $show_on_profile,
  1751. $attrs,
  1752. $uid=null) {
  1753. return $this->call_method('facebook.marketplace.createListing',
  1754. array('listing_id' => $listing_id,
  1755. 'show_on_profile' => $show_on_profile,
  1756. 'listing_attrs' => json_encode($attrs),
  1757. 'uid' => $uid));
  1758. }
  1759. /////////////////////////////////////////////////////////////////////////////
  1760. // Data Store API
  1761. /**
  1762. * Set a user preference.
  1763. *
  1764. * @param pref_id preference identifier (0-200)
  1765. * @param value preferece's value
  1766. * @param uid the user id (defaults to current session user)
  1767. * @error
  1768. * API_EC_DATA_DATABASE_ERROR
  1769. * API_EC_PARAM
  1770. * API_EC_DATA_QUOTA_EXCEEDED
  1771. * API_EC_DATA_UNKNOWN_ERROR
  1772. * API_EC_PERMISSION_OTHER_USER
  1773. */
  1774. public function &data_setUserPreference($pref_id, $value, $uid = null) {
  1775. return $this->call_method('facebook.data.setUserPreference',
  1776. array('pref_id' => $pref_id,
  1777. 'value' => $value,
  1778. 'uid' => $this->get_uid($uid)));
  1779. }
  1780. /**
  1781. * Set a user's all preferences for this application.
  1782. *
  1783. * @param values preferece values in an associative arrays
  1784. * @param replace whether to replace all existing preferences or
  1785. * merge into them.
  1786. * @param uid the user id (defaults to current session user)
  1787. * @error
  1788. * API_EC_DATA_DATABASE_ERROR
  1789. * API_EC_PARAM
  1790. * API_EC_DATA_QUOTA_EXCEEDED
  1791. * API_EC_DATA_UNKNOWN_ERROR
  1792. * API_EC_PERMISSION_OTHER_USER
  1793. */
  1794. public function &data_setUserPreferences($values,
  1795. $replace = false,
  1796. $uid = null) {
  1797. return $this->call_method('facebook.data.setUserPreferences',
  1798. array('values' => json_encode($values),
  1799. 'replace' => $replace,
  1800. 'uid' => $this->get_uid($uid)));
  1801. }
  1802. /**
  1803. * Get a user preference.
  1804. *
  1805. * @param pref_id preference identifier (0-200)
  1806. * @param uid the user id (defaults to current session user)
  1807. * @return preference's value
  1808. * @error
  1809. * API_EC_DATA_DATABASE_ERROR
  1810. * API_EC_PARAM
  1811. * API_EC_DATA_QUOTA_EXCEEDED
  1812. * API_EC_DATA_UNKNOWN_ERROR
  1813. * API_EC_PERMISSION_OTHER_USER
  1814. */
  1815. public function &data_getUserPreference($pref_id, $uid = null) {
  1816. return $this->call_method('facebook.data.getUserPreference',
  1817. array('pref_id' => $pref_id,
  1818. 'uid' => $this->get_uid($uid)));
  1819. }
  1820. /**
  1821. * Get a user preference.
  1822. *
  1823. * @param uid the user id (defaults to current session user)
  1824. * @return preference values
  1825. * @error
  1826. * API_EC_DATA_DATABASE_ERROR
  1827. * API_EC_DATA_QUOTA_EXCEEDED
  1828. * API_EC_DATA_UNKNOWN_ERROR
  1829. * API_EC_PERMISSION_OTHER_USER
  1830. */
  1831. public function &data_getUserPreferences($uid = null) {
  1832. return $this->call_method('facebook.data.getUserPreferences',
  1833. array('uid' => $this->get_uid($uid)));
  1834. }
  1835. /**
  1836. * Create a new object type.
  1837. *
  1838. * @param name object type's name
  1839. * @error
  1840. * API_EC_DATA_DATABASE_ERROR
  1841. * API_EC_DATA_OBJECT_ALREADY_EXISTS
  1842. * API_EC_PARAM
  1843. * API_EC_PERMISSION
  1844. * API_EC_DATA_INVALID_OPERATION
  1845. * API_EC_DATA_QUOTA_EXCEEDED
  1846. * API_EC_DATA_UNKNOWN_ERROR
  1847. */
  1848. public function &data_createObjectType($name) {
  1849. return $this->call_method('facebook.data.createObjectType',
  1850. array('name' => $name));
  1851. }
  1852. /**
  1853. * Delete an object type.
  1854. *
  1855. * @param obj_type object type's name
  1856. * @error
  1857. * API_EC_DATA_DATABASE_ERROR
  1858. * API_EC_DATA_OBJECT_NOT_FOUND
  1859. * API_EC_PARAM
  1860. * API_EC_PERMISSION
  1861. * API_EC_DATA_INVALID_OPERATION
  1862. * API_EC_DATA_QUOTA_EXCEEDED
  1863. * API_EC_DATA_UNKNOWN_ERROR
  1864. */
  1865. public function &data_dropObjectType($obj_type) {
  1866. return $this->call_method('facebook.data.dropObjectType',
  1867. array('obj_type' => $obj_type));
  1868. }
  1869. /**
  1870. * Rename an object type.
  1871. *
  1872. * @param obj_type object type's name
  1873. * @param new_name new object type's name
  1874. * @error
  1875. * API_EC_DATA_DATABASE_ERROR
  1876. * API_EC_DATA_OBJECT_NOT_FOUND
  1877. * API_EC_DATA_OBJECT_ALREADY_EXISTS
  1878. * API_EC_PARAM
  1879. * API_EC_PERMISSION
  1880. * API_EC_DATA_INVALID_OPERATION
  1881. * API_EC_DATA_QUOTA_EXCEEDED
  1882. * API_EC_DATA_UNKNOWN_ERROR
  1883. */
  1884. public function &data_renameObjectType($obj_type, $new_name) {
  1885. return $this->call_method('facebook.data.renameObjectType',
  1886. array('obj_type' => $obj_type,
  1887. 'new_name' => $new_name));
  1888. }
  1889. /**
  1890. * Add a new property to an object type.
  1891. *
  1892. * @param obj_type object type's name
  1893. * @param prop_name name of the property to add
  1894. * @param prop_type 1: integer; 2: string; 3: text blob
  1895. * @error
  1896. * API_EC_DATA_DATABASE_ERROR
  1897. * API_EC_DATA_OBJECT_ALREADY_EXISTS
  1898. * API_EC_PARAM
  1899. * API_EC_PERMISSION
  1900. * API_EC_DATA_INVALID_OPERATION
  1901. * API_EC_DATA_QUOTA_EXCEEDED
  1902. * API_EC_DATA_UNKNOWN_ERROR
  1903. */
  1904. public function &data_defineObjectProperty($obj_type,
  1905. $prop_name,
  1906. $prop_type) {
  1907. return $this->call_method('facebook.data.defineObjectProperty',
  1908. array('obj_type' => $obj_type,
  1909. 'prop_name' => $prop_name,
  1910. 'prop_type' => $prop_type));
  1911. }
  1912. /**
  1913. * Remove a previously defined property from an object type.
  1914. *
  1915. * @param obj_type object type's name
  1916. * @param prop_name name of the property to remove
  1917. * @error
  1918. * API_EC_DATA_DATABASE_ERROR
  1919. * API_EC_DATA_OBJECT_NOT_FOUND
  1920. * API_EC_PARAM
  1921. * API_EC_PERMISSION
  1922. * API_EC_DATA_INVALID_OPERATION
  1923. * API_EC_DATA_QUOTA_EXCEEDED
  1924. * API_EC_DATA_UNKNOWN_ERROR
  1925. */
  1926. public function &data_undefineObjectProperty($obj_type, $prop_name) {
  1927. return $this->call_method('facebook.data.undefineObjectProperty',
  1928. array('obj_type' => $obj_type,
  1929. 'prop_name' => $prop_name));
  1930. }
  1931. /**
  1932. * Rename a previously defined property of an object type.
  1933. *
  1934. * @param obj_type object type's name
  1935. * @param prop_name name of the property to rename
  1936. * @param new_name new name to use
  1937. * @error
  1938. * API_EC_DATA_DATABASE_ERROR
  1939. * API_EC_DATA_OBJECT_NOT_FOUND
  1940. * API_EC_DATA_OBJECT_ALREADY_EXISTS
  1941. * API_EC_PARAM
  1942. * API_EC_PERMISSION
  1943. * API_EC_DATA_INVALID_OPERATION
  1944. * API_EC_DATA_QUOTA_EXCEEDED
  1945. * API_EC_DATA_UNKNOWN_ERROR
  1946. */
  1947. public function &data_renameObjectProperty($obj_type, $prop_name,
  1948. $new_name) {
  1949. return $this->call_method('facebook.data.renameObjectProperty',
  1950. array('obj_type' => $obj_type,
  1951. 'prop_name' => $prop_name,
  1952. 'new_name' => $new_name));
  1953. }
  1954. /**
  1955. * Retrieve a list of all object types that have defined for the application.
  1956. *
  1957. * @return a list of object type names
  1958. * @error
  1959. * API_EC_DATA_DATABASE_ERROR
  1960. * API_EC_PERMISSION
  1961. * API_EC_DATA_QUOTA_EXCEEDED
  1962. * API_EC_DATA_UNKNOWN_ERROR
  1963. */
  1964. public function &data_getObjectTypes() {
  1965. return $this->call_method('facebook.data.getObjectTypes');
  1966. }
  1967. /**
  1968. * Get definitions of all properties of an object type.
  1969. *
  1970. * @param obj_type object type's name
  1971. * @return pairs of property name and property types
  1972. * @error
  1973. * API_EC_DATA_DATABASE_ERROR
  1974. * API_EC_PARAM
  1975. * API_EC_PERMISSION
  1976. * API_EC_DATA_OBJECT_NOT_FOUND
  1977. * API_EC_DATA_QUOTA_EXCEEDED
  1978. * API_EC_DATA_UNKNOWN_ERROR
  1979. */
  1980. public function &data_getObjectType($obj_type) {
  1981. return $this->call_method('facebook.data.getObjectType',
  1982. array('obj_type' => $obj_type));
  1983. }
  1984. /**
  1985. * Create a new object.
  1986. *
  1987. * @param obj_type object type's name
  1988. * @param properties (optional) properties to set initially
  1989. * @return newly created object's id
  1990. * @error
  1991. * API_EC_DATA_DATABASE_ERROR
  1992. * API_EC_PARAM
  1993. * API_EC_PERMISSION
  1994. * API_EC_DATA_INVALID_OPERATION
  1995. * API_EC_DATA_QUOTA_EXCEEDED
  1996. * API_EC_DATA_UNKNOWN_ERROR
  1997. */
  1998. public function &data_createObject($obj_type, $properties = null) {
  1999. return $this->call_method('facebook.data.createObject',
  2000. array('obj_type' => $obj_type,
  2001. 'properties' => json_encode($properties)));
  2002. }
  2003. /**
  2004. * Update an existing object.
  2005. *
  2006. * @param obj_id object's id
  2007. * @param properties new properties
  2008. * @param replace true for replacing existing properties;
  2009. * false for merging
  2010. * @error
  2011. * API_EC_DATA_DATABASE_ERROR
  2012. * API_EC_DATA_OBJECT_NOT_FOUND
  2013. * API_EC_PARAM
  2014. * API_EC_PERMISSION
  2015. * API_EC_DATA_INVALID_OPERATION
  2016. * API_EC_DATA_QUOTA_EXCEEDED
  2017. * API_EC_DATA_UNKNOWN_ERROR
  2018. */
  2019. public function &data_updateObject($obj_id, $properties, $replace = false) {
  2020. return $this->call_method('facebook.data.updateObject',
  2021. array('obj_id' => $obj_id,
  2022. 'properties' => json_encode($properties),
  2023. 'replace' => $replace));
  2024. }
  2025. /**
  2026. * Delete an existing object.
  2027. *
  2028. * @param obj_id object's id
  2029. * @error
  2030. * API_EC_DATA_DATABASE_ERROR
  2031. * API_EC_DATA_OBJECT_NOT_FOUND
  2032. * API_EC_PARAM
  2033. * API_EC_PERMISSION
  2034. * API_EC_DATA_INVALID_OPERATION
  2035. * API_EC_DATA_QUOTA_EXCEEDED
  2036. * API_EC_DATA_UNKNOWN_ERROR
  2037. */
  2038. public function &data_deleteObject($obj_id) {
  2039. return $this->call_method('facebook.data.deleteObject',
  2040. array('obj_id' => $obj_id));
  2041. }
  2042. /**
  2043. * Delete a list of objects.
  2044. *
  2045. * @param obj_ids objects to delete
  2046. * @error
  2047. * API_EC_DATA_DATABASE_ERROR
  2048. * API_EC_PARAM
  2049. * API_EC_PERMISSION
  2050. * API_EC_DATA_INVALID_OPERATION
  2051. * API_EC_DATA_QUOTA_EXCEEDED
  2052. * API_EC_DATA_UNKNOWN_ERROR
  2053. */
  2054. public function &data_deleteObjects($obj_ids) {
  2055. return $this->call_method('facebook.data.deleteObjects',
  2056. array('obj_ids' => json_encode($obj_ids)));
  2057. }
  2058. /**
  2059. * Get a single property value of an object.
  2060. *
  2061. * @param obj_id object's id
  2062. * @param prop_name individual property's name
  2063. * @return individual property's value
  2064. * @error
  2065. * API_EC_DATA_DATABASE_ERROR
  2066. * API_EC_DATA_OBJECT_NOT_FOUND
  2067. * API_EC_PARAM
  2068. * API_EC_PERMISSION
  2069. * API_EC_DATA_INVALID_OPERATION
  2070. * API_EC_DATA_QUOTA_EXCEEDED
  2071. * API_EC_DATA_UNKNOWN_ERROR
  2072. */
  2073. public function &data_getObjectProperty($obj_id, $prop_name) {
  2074. return $this->call_method('facebook.data.getObjectProperty',
  2075. array('obj_id' => $obj_id,
  2076. 'prop_name' => $prop_name));
  2077. }
  2078. /**
  2079. * Get properties of an object.
  2080. *
  2081. * @param obj_id object's id
  2082. * @param prop_names (optional) properties to return; null for all.
  2083. * @return specified properties of an object
  2084. * @error
  2085. * API_EC_DATA_DATABASE_ERROR
  2086. * API_EC_DATA_OBJECT_NOT_FOUND
  2087. * API_EC_PARAM
  2088. * API_EC_PERMISSION
  2089. * API_EC_DATA_INVALID_OPERATION
  2090. * API_EC_DATA_QUOTA_EXCEEDED
  2091. * API_EC_DATA_UNKNOWN_ERROR
  2092. */
  2093. public function &data_getObject($obj_id, $prop_names = null) {
  2094. return $this->call_method('facebook.data.getObject',
  2095. array('obj_id' => $obj_id,
  2096. 'prop_names' => json_encode($prop_names)));
  2097. }
  2098. /**
  2099. * Get properties of a list of objects.
  2100. *
  2101. * @param obj_ids object ids
  2102. * @param prop_names (optional) properties to return; null for all.
  2103. * @return specified properties of an object
  2104. * @error
  2105. * API_EC_DATA_DATABASE_ERROR
  2106. * API_EC_DATA_OBJECT_NOT_FOUND
  2107. * API_EC_PARAM
  2108. * API_EC_PERMISSION
  2109. * API_EC_DATA_INVALID_OPERATION
  2110. * API_EC_DATA_QUOTA_EXCEEDED
  2111. * API_EC_DATA_UNKNOWN_ERROR
  2112. */
  2113. public function &data_getObjects($obj_ids, $prop_names = null) {
  2114. return $this->call_method('facebook.data.getObjects',
  2115. array('obj_ids' => json_encode($obj_ids),
  2116. 'prop_names' => json_encode($prop_names)));
  2117. }
  2118. /**
  2119. * Set a single property value of an object.
  2120. *
  2121. * @param obj_id object's id
  2122. * @param prop_name individual property's name
  2123. * @param prop_value new value to set
  2124. * @error
  2125. * API_EC_DATA_DATABASE_ERROR
  2126. * API_EC_DATA_OBJECT_NOT_FOUND
  2127. * API_EC_PARAM
  2128. * API_EC_PERMISSION
  2129. * API_EC_DATA_INVALID_OPERATION
  2130. * API_EC_DATA_QUOTA_EXCEEDED
  2131. * API_EC_DATA_UNKNOWN_ERROR
  2132. */
  2133. public function &data_setObjectProperty($obj_id, $prop_name,
  2134. $prop_value) {
  2135. return $this->call_method('facebook.data.setObjectProperty',
  2136. array('obj_id' => $obj_id,
  2137. 'prop_name' => $prop_name,
  2138. 'prop_value' => $prop_value));
  2139. }
  2140. /**
  2141. * Read hash value by key.
  2142. *
  2143. * @param obj_type object type's name
  2144. * @param key hash key
  2145. * @param prop_name (optional) individual property's name
  2146. * @return hash value
  2147. * @error
  2148. * API_EC_DATA_DATABASE_ERROR
  2149. * API_EC_PARAM
  2150. * API_EC_PERMISSION
  2151. * API_EC_DATA_INVALID_OPERATION
  2152. * API_EC_DATA_QUOTA_EXCEEDED
  2153. * API_EC_DATA_UNKNOWN_ERROR
  2154. */
  2155. public function &data_getHashValue($obj_type, $key, $prop_name = null) {
  2156. return $this->call_method('facebook.data.getHashValue',
  2157. array('obj_type' => $obj_type,
  2158. 'key' => $key,
  2159. 'prop_name' => $prop_name));
  2160. }
  2161. /**
  2162. * Write hash value by key.
  2163. *
  2164. * @param obj_type object type's name
  2165. * @param key hash key
  2166. * @param value hash value
  2167. * @param prop_name (optional) individual property's name
  2168. * @error
  2169. * API_EC_DATA_DATABASE_ERROR
  2170. * API_EC_PARAM
  2171. * API_EC_PERMISSION
  2172. * API_EC_DATA_INVALID_OPERATION
  2173. * API_EC_DATA_QUOTA_EXCEEDED
  2174. * API_EC_DATA_UNKNOWN_ERROR
  2175. */
  2176. public function &data_setHashValue($obj_type,
  2177. $key,
  2178. $value,
  2179. $prop_name = null) {
  2180. return $this->call_method('facebook.data.setHashValue',
  2181. array('obj_type' => $obj_type,
  2182. 'key' => $key,
  2183. 'value' => $value,
  2184. 'prop_name' => $prop_name));
  2185. }
  2186. /**
  2187. * Increase a hash value by specified increment atomically.
  2188. *
  2189. * @param obj_type object type's name
  2190. * @param key hash key
  2191. * @param prop_name individual property's name
  2192. * @param increment (optional) default is 1
  2193. * @return incremented hash value
  2194. * @error
  2195. * API_EC_DATA_DATABASE_ERROR
  2196. * API_EC_PARAM
  2197. * API_EC_PERMISSION
  2198. * API_EC_DATA_INVALID_OPERATION
  2199. * API_EC_DATA_QUOTA_EXCEEDED
  2200. * API_EC_DATA_UNKNOWN_ERROR
  2201. */
  2202. public function &data_incHashValue($obj_type,
  2203. $key,
  2204. $prop_name,
  2205. $increment = 1) {
  2206. return $this->call_method('facebook.data.incHashValue',
  2207. array('obj_type' => $obj_type,
  2208. 'key' => $key,
  2209. 'prop_name' => $prop_name,
  2210. 'increment' => $increment));
  2211. }
  2212. /**
  2213. * Remove a hash key and its values.
  2214. *
  2215. * @param obj_type object type's name
  2216. * @param key hash key
  2217. * @error
  2218. * API_EC_DATA_DATABASE_ERROR
  2219. * API_EC_PARAM
  2220. * API_EC_PERMISSION
  2221. * API_EC_DATA_INVALID_OPERATION
  2222. * API_EC_DATA_QUOTA_EXCEEDED
  2223. * API_EC_DATA_UNKNOWN_ERROR
  2224. */
  2225. public function &data_removeHashKey($obj_type, $key) {
  2226. return $this->call_method('facebook.data.removeHashKey',
  2227. array('obj_type' => $obj_type,
  2228. 'key' => $key));
  2229. }
  2230. /**
  2231. * Remove hash keys and their values.
  2232. *
  2233. * @param obj_type object type's name
  2234. * @param keys hash keys
  2235. * @error
  2236. * API_EC_DATA_DATABASE_ERROR
  2237. * API_EC_PARAM
  2238. * API_EC_PERMISSION
  2239. * API_EC_DATA_INVALID_OPERATION
  2240. * API_EC_DATA_QUOTA_EXCEEDED
  2241. * API_EC_DATA_UNKNOWN_ERROR
  2242. */
  2243. public function &data_removeHashKeys($obj_type, $keys) {
  2244. return $this->call_method('facebook.data.removeHashKeys',
  2245. array('obj_type' => $obj_type,
  2246. 'keys' => json_encode($keys)));
  2247. }
  2248. /**
  2249. * Define an object association.
  2250. *
  2251. * @param name name of this association
  2252. * @param assoc_type 1: one-way 2: two-way symmetric 3: two-way asymmetric
  2253. * @param assoc_info1 needed info about first object type
  2254. * @param assoc_info2 needed info about second object type
  2255. * @param inverse (optional) name of reverse association
  2256. * @error
  2257. * API_EC_DATA_DATABASE_ERROR
  2258. * API_EC_DATA_OBJECT_ALREADY_EXISTS
  2259. * API_EC_PARAM
  2260. * API_EC_PERMISSION
  2261. * API_EC_DATA_INVALID_OPERATION
  2262. * API_EC_DATA_QUOTA_EXCEEDED
  2263. * API_EC_DATA_UNKNOWN_ERROR
  2264. */
  2265. public function &data_defineAssociation($name, $assoc_type, $assoc_info1,
  2266. $assoc_info2, $inverse = null) {
  2267. return $this->call_method('facebook.data.defineAssociation',
  2268. array('name' => $name,
  2269. 'assoc_type' => $assoc_type,
  2270. 'assoc_info1' => json_encode($assoc_info1),
  2271. 'assoc_info2' => json_encode($assoc_info2),
  2272. 'inverse' => $inverse));
  2273. }
  2274. /**
  2275. * Undefine an object association.
  2276. *
  2277. * @param name name of this association
  2278. * @error
  2279. * API_EC_DATA_DATABASE_ERROR
  2280. * API_EC_DATA_OBJECT_NOT_FOUND
  2281. * API_EC_PARAM
  2282. * API_EC_PERMISSION
  2283. * API_EC_DATA_INVALID_OPERATION
  2284. * API_EC_DATA_QUOTA_EXCEEDED
  2285. * API_EC_DATA_UNKNOWN_ERROR
  2286. */
  2287. public function &data_undefineAssociation($name) {
  2288. return $this->call_method('facebook.data.undefineAssociation',
  2289. array('name' => $name));
  2290. }
  2291. /**
  2292. * Rename an object association or aliases.
  2293. *
  2294. * @param name name of this association
  2295. * @param new_name (optional) new name of this association
  2296. * @param new_alias1 (optional) new alias for object type 1
  2297. * @param new_alias2 (optional) new alias for object type 2
  2298. * @error
  2299. * API_EC_DATA_DATABASE_ERROR
  2300. * API_EC_DATA_OBJECT_ALREADY_EXISTS
  2301. * API_EC_DATA_OBJECT_NOT_FOUND
  2302. * API_EC_PARAM
  2303. * API_EC_PERMISSION
  2304. * API_EC_DATA_INVALID_OPERATION
  2305. * API_EC_DATA_QUOTA_EXCEEDED
  2306. * API_EC_DATA_UNKNOWN_ERROR
  2307. */
  2308. public function &data_renameAssociation($name, $new_name, $new_alias1 = null,
  2309. $new_alias2 = null) {
  2310. return $this->call_method('facebook.data.renameAssociation',
  2311. array('name' => $name,
  2312. 'new_name' => $new_name,
  2313. 'new_alias1' => $new_alias1,
  2314. 'new_alias2' => $new_alias2));
  2315. }
  2316. /**
  2317. * Get definition of an object association.
  2318. *
  2319. * @param name name of this association
  2320. * @return specified association
  2321. * @error
  2322. * API_EC_DATA_DATABASE_ERROR
  2323. * API_EC_DATA_OBJECT_NOT_FOUND
  2324. * API_EC_PARAM
  2325. * API_EC_PERMISSION
  2326. * API_EC_DATA_QUOTA_EXCEEDED
  2327. * API_EC_DATA_UNKNOWN_ERROR
  2328. */
  2329. public function &data_getAssociationDefinition($name) {
  2330. return $this->call_method('facebook.data.getAssociationDefinition',
  2331. array('name' => $name));
  2332. }
  2333. /**
  2334. * Get definition of all associations.
  2335. *
  2336. * @return all defined associations
  2337. * @error
  2338. * API_EC_DATA_DATABASE_ERROR
  2339. * API_EC_PERMISSION
  2340. * API_EC_DATA_QUOTA_EXCEEDED
  2341. * API_EC_DATA_UNKNOWN_ERROR
  2342. */
  2343. public function &data_getAssociationDefinitions() {
  2344. return $this->call_method('facebook.data.getAssociationDefinitions',
  2345. array());
  2346. }
  2347. /**
  2348. * Create or modify an association between two objects.
  2349. *
  2350. * @param name name of association
  2351. * @param obj_id1 id of first object
  2352. * @param obj_id2 id of second object
  2353. * @param data (optional) extra string data to store
  2354. * @param assoc_time (optional) extra time data; default to creation time
  2355. * @error
  2356. * API_EC_DATA_DATABASE_ERROR
  2357. * API_EC_PARAM
  2358. * API_EC_PERMISSION
  2359. * API_EC_DATA_INVALID_OPERATION
  2360. * API_EC_DATA_QUOTA_EXCEEDED
  2361. * API_EC_DATA_UNKNOWN_ERROR
  2362. */
  2363. public function &data_setAssociation($name, $obj_id1, $obj_id2, $data = null,
  2364. $assoc_time = null) {
  2365. return $this->call_method('facebook.data.setAssociation',
  2366. array('name' => $name,
  2367. 'obj_id1' => $obj_id1,
  2368. 'obj_id2' => $obj_id2,
  2369. 'data' => $data,
  2370. 'assoc_time' => $assoc_time));
  2371. }
  2372. /**
  2373. * Create or modify associations between objects.
  2374. *
  2375. * @param assocs associations to set
  2376. * @param name (optional) name of association
  2377. * @error
  2378. * API_EC_DATA_DATABASE_ERROR
  2379. * API_EC_PARAM
  2380. * API_EC_PERMISSION
  2381. * API_EC_DATA_INVALID_OPERATION
  2382. * API_EC_DATA_QUOTA_EXCEEDED
  2383. * API_EC_DATA_UNKNOWN_ERROR
  2384. */
  2385. public function &data_setAssociations($assocs, $name = null) {
  2386. return $this->call_method('facebook.data.setAssociations',
  2387. array('assocs' => json_encode($assocs),
  2388. 'name' => $name));
  2389. }
  2390. /**
  2391. * Remove an association between two objects.
  2392. *
  2393. * @param name name of association
  2394. * @param obj_id1 id of first object
  2395. * @param obj_id2 id of second object
  2396. * @error
  2397. * API_EC_DATA_DATABASE_ERROR
  2398. * API_EC_DATA_OBJECT_NOT_FOUND
  2399. * API_EC_PARAM
  2400. * API_EC_PERMISSION
  2401. * API_EC_DATA_QUOTA_EXCEEDED
  2402. * API_EC_DATA_UNKNOWN_ERROR
  2403. */
  2404. public function &data_removeAssociation($name, $obj_id1, $obj_id2) {
  2405. return $this->call_method('facebook.data.removeAssociation',
  2406. array('name' => $name,
  2407. 'obj_id1' => $obj_id1,
  2408. 'obj_id2' => $obj_id2));
  2409. }
  2410. /**
  2411. * Remove associations between objects by specifying pairs of object ids.
  2412. *
  2413. * @param assocs associations to remove
  2414. * @param name (optional) name of association
  2415. * @error
  2416. * API_EC_DATA_DATABASE_ERROR
  2417. * API_EC_DATA_OBJECT_NOT_FOUND
  2418. * API_EC_PARAM
  2419. * API_EC_PERMISSION
  2420. * API_EC_DATA_QUOTA_EXCEEDED
  2421. * API_EC_DATA_UNKNOWN_ERROR
  2422. */
  2423. public function &data_removeAssociations($assocs, $name = null) {
  2424. return $this->call_method('facebook.data.removeAssociations',
  2425. array('assocs' => json_encode($assocs),
  2426. 'name' => $name));
  2427. }
  2428. /**
  2429. * Remove associations between objects by specifying one object id.
  2430. *
  2431. * @param name name of association
  2432. * @param obj_id who's association to remove
  2433. * @error
  2434. * API_EC_DATA_DATABASE_ERROR
  2435. * API_EC_DATA_OBJECT_NOT_FOUND
  2436. * API_EC_PARAM
  2437. * API_EC_PERMISSION
  2438. * API_EC_DATA_INVALID_OPERATION
  2439. * API_EC_DATA_QUOTA_EXCEEDED
  2440. * API_EC_DATA_UNKNOWN_ERROR
  2441. */
  2442. public function &data_removeAssociatedObjects($name, $obj_id) {
  2443. return $this->call_method('facebook.data.removeAssociatedObjects',
  2444. array('name' => $name,
  2445. 'obj_id' => $obj_id));
  2446. }
  2447. /**
  2448. * Retrieve a list of associated objects.
  2449. *
  2450. * @param name name of association
  2451. * @param obj_id who's association to retrieve
  2452. * @param no_data only return object ids
  2453. * @return associated objects
  2454. * @error
  2455. * API_EC_DATA_DATABASE_ERROR
  2456. * API_EC_DATA_OBJECT_NOT_FOUND
  2457. * API_EC_PARAM
  2458. * API_EC_PERMISSION
  2459. * API_EC_DATA_INVALID_OPERATION
  2460. * API_EC_DATA_QUOTA_EXCEEDED
  2461. * API_EC_DATA_UNKNOWN_ERROR
  2462. */
  2463. public function &data_getAssociatedObjects($name, $obj_id, $no_data = true) {
  2464. return $this->call_method('facebook.data.getAssociatedObjects',
  2465. array('name' => $name,
  2466. 'obj_id' => $obj_id,
  2467. 'no_data' => $no_data));
  2468. }
  2469. /**
  2470. * Count associated objects.
  2471. *
  2472. * @param name name of association
  2473. * @param obj_id who's association to retrieve
  2474. * @return associated object's count
  2475. * @error
  2476. * API_EC_DATA_DATABASE_ERROR
  2477. * API_EC_DATA_OBJECT_NOT_FOUND
  2478. * API_EC_PARAM
  2479. * API_EC_PERMISSION
  2480. * API_EC_DATA_INVALID_OPERATION
  2481. * API_EC_DATA_QUOTA_EXCEEDED
  2482. * API_EC_DATA_UNKNOWN_ERROR
  2483. */
  2484. public function &data_getAssociatedObjectCount($name, $obj_id) {
  2485. return $this->call_method('facebook.data.getAssociatedObjectCount',
  2486. array('name' => $name,
  2487. 'obj_id' => $obj_id));
  2488. }
  2489. /**
  2490. * Get a list of associated object counts.
  2491. *
  2492. * @param name name of association
  2493. * @param obj_ids whose association to retrieve
  2494. * @return associated object counts
  2495. * @error
  2496. * API_EC_DATA_DATABASE_ERROR
  2497. * API_EC_DATA_OBJECT_NOT_FOUND
  2498. * API_EC_PARAM
  2499. * API_EC_PERMISSION
  2500. * API_EC_DATA_INVALID_OPERATION
  2501. * API_EC_DATA_QUOTA_EXCEEDED
  2502. * API_EC_DATA_UNKNOWN_ERROR
  2503. */
  2504. public function &data_getAssociatedObjectCounts($name, $obj_ids) {
  2505. return $this->call_method('facebook.data.getAssociatedObjectCounts',
  2506. array('name' => $name,
  2507. 'obj_ids' => json_encode($obj_ids)));
  2508. }
  2509. /**
  2510. * Find all associations between two objects.
  2511. *
  2512. * @param obj_id1 id of first object
  2513. * @param obj_id2 id of second object
  2514. * @param no_data only return association names without data
  2515. * @return all associations between objects
  2516. * @error
  2517. * API_EC_DATA_DATABASE_ERROR
  2518. * API_EC_PARAM
  2519. * API_EC_PERMISSION
  2520. * API_EC_DATA_QUOTA_EXCEEDED
  2521. * API_EC_DATA_UNKNOWN_ERROR
  2522. */
  2523. public function &data_getAssociations($obj_id1, $obj_id2, $no_data = true) {
  2524. return $this->call_method('facebook.data.getAssociations',
  2525. array('obj_id1' => $obj_id1,
  2526. 'obj_id2' => $obj_id2,
  2527. 'no_data' => $no_data));
  2528. }
  2529. /**
  2530. * Get the properties that you have set for an app.
  2531. *
  2532. * @param properties List of properties names to fetch
  2533. *
  2534. * @return array A map from property name to value
  2535. */
  2536. public function admin_getAppProperties($properties) {
  2537. return json_decode(
  2538. $this->call_method('facebook.admin.getAppProperties',
  2539. array('properties' => json_encode($properties))), true);
  2540. }
  2541. /**
  2542. * Set properties for an app.
  2543. *
  2544. * @param properties A map from property names to values
  2545. *
  2546. * @return bool true on success
  2547. */
  2548. public function admin_setAppProperties($properties) {
  2549. return $this->call_method('facebook.admin.setAppProperties',
  2550. array('properties' => json_encode($properties)));
  2551. }
  2552. /**
  2553. * Returns the allocation limit value for a specified integration point name
  2554. * Integration point names are defined in lib/api/karma/constants.php in the
  2555. * limit_map.
  2556. *
  2557. * @param string $integration_point_name Name of an integration point
  2558. * (see developer wiki for list).
  2559. * @param int $uid Specific user to check the limit.
  2560. *
  2561. * @return int Integration point allocation value
  2562. */
  2563. public function &admin_getAllocation($integration_point_name, $uid=null) {
  2564. return $this->call_method('facebook.admin.getAllocation',
  2565. array('integration_point_name' => $integration_point_name,
  2566. 'uid' => $uid));
  2567. }
  2568. /**
  2569. * Returns values for the specified metrics for the current application, in
  2570. * the given time range. The metrics are collected for fixed-length periods,
  2571. * and the times represent midnight at the end of each period.
  2572. *
  2573. * @param start_time unix time for the start of the range
  2574. * @param end_time unix time for the end of the range
  2575. * @param period number of seconds in the desired period
  2576. * @param metrics list of metrics to look up
  2577. *
  2578. * @return array A map of the names and values for those metrics
  2579. */
  2580. public function &admin_getMetrics($start_time, $end_time, $period, $metrics) {
  2581. return $this->call_method('admin.getMetrics',
  2582. array('start_time' => $start_time,
  2583. 'end_time' => $end_time,
  2584. 'period' => $period,
  2585. 'metrics' => json_encode($metrics)));
  2586. }
  2587. /**
  2588. * Sets application restriction info.
  2589. *
  2590. * Applications can restrict themselves to only a limited user demographic
  2591. * based on users' age and/or location or based on static predefined types
  2592. * specified by facebook for specifying diff age restriction for diff
  2593. * locations.
  2594. *
  2595. * @param array $restriction_info The age restriction settings to set.
  2596. *
  2597. * @return bool true on success
  2598. */
  2599. public function admin_setRestrictionInfo($restriction_info = null) {
  2600. $restriction_str = null;
  2601. if (!empty($restriction_info)) {
  2602. $restriction_str = json_encode($restriction_info);
  2603. }
  2604. return $this->call_method('admin.setRestrictionInfo',
  2605. array('restriction_str' => $restriction_str));
  2606. }
  2607. /**
  2608. * Gets application restriction info.
  2609. *
  2610. * Applications can restrict themselves to only a limited user demographic
  2611. * based on users' age and/or location or based on static predefined types
  2612. * specified by facebook for specifying diff age restriction for diff
  2613. * locations.
  2614. *
  2615. * @return array The age restriction settings for this application.
  2616. */
  2617. public function admin_getRestrictionInfo() {
  2618. return json_decode(
  2619. $this->call_method('admin.getRestrictionInfo'),
  2620. true);
  2621. }
  2622. /**
  2623. * Bans a list of users from the app. Banned users can't
  2624. * access the app's canvas page and forums.
  2625. *
  2626. * @param array $uids an array of user ids
  2627. * @return bool true on success
  2628. */
  2629. public function admin_banUsers($uids) {
  2630. return $this->call_method(
  2631. 'admin.banUsers', array('uids' => json_encode($uids)));
  2632. }
  2633. /**
  2634. * Unban users that have been previously banned with
  2635. * admin_banUsers().
  2636. *
  2637. * @param array $uids an array of user ids
  2638. * @return bool true on success
  2639. */
  2640. public function admin_unbanUsers($uids) {
  2641. return $this->call_method(
  2642. 'admin.unbanUsers', array('uids' => json_encode($uids)));
  2643. }
  2644. /**
  2645. * Gets the list of users that have been banned from the application.
  2646. * $uids is an optional parameter that filters the result with the list
  2647. * of provided user ids. If $uids is provided,
  2648. * only banned user ids that are contained in $uids are returned.
  2649. *
  2650. * @param array $uids an array of user ids to filter by
  2651. * @return bool true on success
  2652. */
  2653. public function admin_getBannedUsers($uids = null) {
  2654. return $this->call_method(
  2655. 'admin.getBannedUsers',
  2656. array('uids' => $uids ? json_encode($uids) : null));
  2657. }
  2658. /* UTILITY FUNCTIONS */
  2659. /**
  2660. * Calls the specified normal POST method with the specified parameters.
  2661. *
  2662. * @param string $method Name of the Facebook method to invoke
  2663. * @param array $params A map of param names => param values
  2664. *
  2665. * @return mixed Result of method call; this returns a reference to support
  2666. * 'delayed returns' when in a batch context.
  2667. * See: http://wiki.developers.facebook.com/index.php/Using_batching_API
  2668. */
  2669. public function &call_method($method, $params = array()) {
  2670. if (!$this->pending_batch()) {
  2671. if ($this->call_as_apikey) {
  2672. $params['call_as_apikey'] = $this->call_as_apikey;
  2673. }
  2674. $data = $this->post_request($method, $params);
  2675. if (empty($params['format']) || strtolower($params['format']) != 'json') {
  2676. $result = $this->convert_xml_to_result($data, $method, $params);
  2677. }
  2678. else {
  2679. $result = json_decode($data, true);
  2680. }
  2681. if (is_array($result) && isset($result['error_code'])) {
  2682. throw new FacebookRestClientException($result['error_msg'],
  2683. $result['error_code']);
  2684. }
  2685. }
  2686. else {
  2687. $result = null;
  2688. $batch_item = array('m' => $method, 'p' => $params, 'r' => & $result);
  2689. $this->batch_queue[] = $batch_item;
  2690. }
  2691. return $result;
  2692. }
  2693. /**
  2694. * Calls the specified file-upload POST method with the specified parameters
  2695. *
  2696. * @param string $method Name of the Facebook method to invoke
  2697. * @param array $params A map of param names => param values
  2698. * @param string $file A path to the file to upload (required)
  2699. *
  2700. * @return array A dictionary representing the response.
  2701. */
  2702. public function call_upload_method($method, $params, $file, $server_addr = null) {
  2703. if (!$this->pending_batch()) {
  2704. if (!file_exists($file)) {
  2705. $code =
  2706. FacebookAPIErrorCodes::API_EC_PARAM;
  2707. $description = FacebookAPIErrorCodes::$api_error_descriptions[$code];
  2708. throw new FacebookRestClientException($description, $code);
  2709. }
  2710. $xml = $this->post_upload_request($method, $params, $file, $server_addr);
  2711. $result = $this->convert_xml_to_result($xml, $method, $params);
  2712. if (is_array($result) && isset($result['error_code'])) {
  2713. throw new FacebookRestClientException($result['error_msg'],
  2714. $result['error_code']);
  2715. }
  2716. }
  2717. else {
  2718. $code =
  2719. FacebookAPIErrorCodes::API_EC_BATCH_METHOD_NOT_ALLOWED_IN_BATCH_MODE;
  2720. $description = FacebookAPIErrorCodes::$api_error_descriptions[$code];
  2721. throw new FacebookRestClientException($description, $code);
  2722. }
  2723. return $result;
  2724. }
  2725. protected function convert_xml_to_result($xml, $method, $params) {
  2726. $sxml = simplexml_load_string($xml);
  2727. $result = self::convert_simplexml_to_array($sxml);
  2728. if (!empty($GLOBALS['facebook_config']['debug'])) {
  2729. // output the raw xml and its corresponding php object, for debugging:
  2730. print '<div style="margin: 10px 30px; padding: 5px; border: 2px solid black; background: gray; color: white; font-size: 12px; font-weight: bold;">';
  2731. $this->cur_id++;
  2732. print $this->cur_id . ': Called ' . $method . ', show ' .
  2733. '<a href=# onclick="return toggleDisplay(' . $this->cur_id . ', \'params\');">Params</a> | '.
  2734. '<a href=# onclick="return toggleDisplay(' . $this->cur_id . ', \'xml\');">XML</a> | '.
  2735. '<a href=# onclick="return toggleDisplay(' . $this->cur_id . ', \'sxml\');">SXML</a> | '.
  2736. '<a href=# onclick="return toggleDisplay(' . $this->cur_id . ', \'php\');">PHP</a>';
  2737. print '<pre id="params'.$this->cur_id.'" style="display: none; overflow: auto;">'.print_r($params, true).'</pre>';
  2738. print '<pre id="xml'.$this->cur_id.'" style="display: none; overflow: auto;">'.htmlspecialchars($xml).'</pre>';
  2739. print '<pre id="php'.$this->cur_id.'" style="display: none; overflow: auto;">'.print_r($result, true).'</pre>';
  2740. print '<pre id="sxml'.$this->cur_id.'" style="display: none; overflow: auto;">'.print_r($sxml, true).'</pre>';
  2741. print '</div>';
  2742. }
  2743. return $result;
  2744. }
  2745. private function finalize_params($method, &$params) {
  2746. $this->add_standard_params($method, $params);
  2747. // we need to do this before signing the params
  2748. $this->convert_array_values_to_json($params);
  2749. $params['sig'] = Facebook::generate_sig($params, $this->secret);
  2750. }
  2751. private function convert_array_values_to_json(&$params) {
  2752. foreach ($params as $key => &$val) {
  2753. if (is_array($val)) {
  2754. $val = json_encode($val);
  2755. }
  2756. }
  2757. }
  2758. private function add_standard_params($method, &$params) {
  2759. if ($this->call_as_apikey) {
  2760. $params['call_as_apikey'] = $this->call_as_apikey;
  2761. }
  2762. $params['method'] = $method;
  2763. $params['session_key'] = $this->session_key;
  2764. $params['api_key'] = $this->api_key;
  2765. $params['call_id'] = microtime(true);
  2766. if ($params['call_id'] <= $this->last_call_id) {
  2767. $params['call_id'] = $this->last_call_id + 0.001;
  2768. }
  2769. $this->last_call_id = $params['call_id'];
  2770. if (!isset($params['v'])) {
  2771. $params['v'] = '1.0';
  2772. }
  2773. if (isset($this->use_ssl_resources) &&
  2774. $this->use_ssl_resources) {
  2775. $params['return_ssl_resources'] = true;
  2776. }
  2777. }
  2778. private function create_post_string($method, $params) {
  2779. $post_params = array();
  2780. foreach ($params as $key => &$val) {
  2781. $post_params[] = $key.'='.urlencode($val);
  2782. }
  2783. return implode('&', $post_params);
  2784. }
  2785. private function run_multipart_http_transaction($method, $params, $file, $server_addr) {
  2786. // the format of this message is specified in RFC1867/RFC1341.
  2787. // we add twenty pseudo-random digits to the end of the boundary string.
  2788. $boundary = '--------------------------FbMuLtIpArT' .
  2789. sprintf("%010d", mt_rand()) .
  2790. sprintf("%010d", mt_rand());
  2791. $content_type = 'multipart/form-data; boundary=' . $boundary;
  2792. // within the message, we prepend two extra hyphens.
  2793. $delimiter = '--' . $boundary;
  2794. $close_delimiter = $delimiter . '--';
  2795. $content_lines = array();
  2796. foreach ($params as $key => &$val) {
  2797. $content_lines[] = $delimiter;
  2798. $content_lines[] = 'Content-Disposition: form-data; name="' . $key . '"';
  2799. $content_lines[] = '';
  2800. $content_lines[] = $val;
  2801. }
  2802. // now add the file data
  2803. $content_lines[] = $delimiter;
  2804. $content_lines[] =
  2805. 'Content-Disposition: form-data; filename="' . $file . '"';
  2806. $content_lines[] = 'Content-Type: application/octet-stream';
  2807. $content_lines[] = '';
  2808. $content_lines[] = file_get_contents($file);
  2809. $content_lines[] = $close_delimiter;
  2810. $content_lines[] = '';
  2811. $content = implode("\r\n", $content_lines);
  2812. return $this->run_http_post_transaction($content_type, $content, $server_addr);
  2813. }
  2814. public function post_request($method, $params) {
  2815. $this->finalize_params($method, $params);
  2816. $post_string = $this->create_post_string($method, $params);
  2817. if ($this->use_curl_if_available && function_exists('curl_init')) {
  2818. $useragent = 'Facebook API PHP5 Client 1.1 (curl) ' . phpversion();
  2819. $ch = curl_init();
  2820. curl_setopt($ch, CURLOPT_URL, $this->server_addr);
  2821. curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string);
  2822. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  2823. curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
  2824. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
  2825. curl_setopt($ch, CURLOPT_TIMEOUT, 30);
  2826. $result = curl_exec($ch);
  2827. curl_close($ch);
  2828. } else {
  2829. $content_type = 'application/x-www-form-urlencoded';
  2830. $content = $post_string;
  2831. $result = $this->run_http_post_transaction($content_type,
  2832. $content,
  2833. $this->server_addr);
  2834. }
  2835. return $result;
  2836. }
  2837. private function post_upload_request($method, $params, $file, $server_addr = null) {
  2838. $server_addr = $server_addr ? $server_addr : $this->server_addr;
  2839. $this->finalize_params($method, $params);
  2840. if ($this->use_curl_if_available && function_exists('curl_init')) {
  2841. // prepending '@' causes cURL to upload the file; the key is ignored.
  2842. $params['_file'] = '@' . $file;
  2843. $useragent = 'Facebook API PHP5 Client 1.1 (curl) ' . phpversion();
  2844. $ch = curl_init();
  2845. curl_setopt($ch, CURLOPT_URL, $server_addr);
  2846. // this has to come before the POSTFIELDS set!
  2847. curl_setopt($ch, CURLOPT_POST, 1 );
  2848. // passing an array gets curl to use the multipart/form-data content type
  2849. curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
  2850. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  2851. curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
  2852. $result = curl_exec($ch);
  2853. curl_close($ch);
  2854. } else {
  2855. $result = $this->run_multipart_http_transaction($method, $params, $file, $server_addr);
  2856. }
  2857. return $result;
  2858. }
  2859. private function run_http_post_transaction($content_type, $content, $server_addr) {
  2860. $user_agent = 'Facebook API PHP5 Client 1.1 (non-curl) ' . phpversion();
  2861. $content_length = strlen($content);
  2862. $context =
  2863. array('http' =>
  2864. array('method' => 'POST',
  2865. 'user_agent' => $user_agent,
  2866. 'header' => 'Content-Type: ' . $content_type . "\r\n" .
  2867. 'Content-Length: ' . $content_length,
  2868. 'content' => $content));
  2869. $context_id = stream_context_create($context);
  2870. $sock = fopen($server_addr, 'r', false, $context_id);
  2871. $result = '';
  2872. if ($sock) {
  2873. while (!feof($sock)) {
  2874. $result .= fgets($sock, 4096);
  2875. }
  2876. fclose($sock);
  2877. }
  2878. return $result;
  2879. }
  2880. public static function convert_simplexml_to_array($sxml) {
  2881. $arr = array();
  2882. if ($sxml) {
  2883. foreach ($sxml as $k => $v) {
  2884. if ($sxml['list']) {
  2885. $arr[] = self::convert_simplexml_to_array($v);
  2886. } else {
  2887. $arr[$k] = self::convert_simplexml_to_array($v);
  2888. }
  2889. }
  2890. }
  2891. if (sizeof($arr) > 0) {
  2892. return $arr;
  2893. } else {
  2894. return (string)$sxml;
  2895. }
  2896. }
  2897. private function get_uid($uid) {
  2898. return $uid ? $uid : $this->user;
  2899. }
  2900. }
  2901. class FacebookRestClientException extends Exception {
  2902. }
  2903. // Supporting methods and values------
  2904. /**
  2905. * Error codes and descriptions for the Facebook API.
  2906. */
  2907. class FacebookAPIErrorCodes {
  2908. const API_EC_SUCCESS = 0;
  2909. /*
  2910. * GENERAL ERRORS
  2911. */
  2912. const API_EC_UNKNOWN = 1;
  2913. const API_EC_SERVICE = 2;
  2914. const API_EC_METHOD = 3;
  2915. const API_EC_TOO_MANY_CALLS = 4;
  2916. const API_EC_BAD_IP = 5;
  2917. const API_EC_HOST_API = 6;
  2918. const API_EC_HOST_UP = 7;
  2919. const API_EC_SECURE = 8;
  2920. const API_EC_RATE = 9;
  2921. const API_EC_PERMISSION_DENIED = 10;
  2922. const API_EC_DEPRECATED = 11;
  2923. const API_EC_VERSION = 12;
  2924. const API_EC_INTERNAL_FQL_ERROR = 13;
  2925. /*
  2926. * PARAMETER ERRORS
  2927. */
  2928. const API_EC_PARAM = 100;
  2929. const API_EC_PARAM_API_KEY = 101;
  2930. const API_EC_PARAM_SESSION_KEY = 102;
  2931. const API_EC_PARAM_CALL_ID = 103;
  2932. const API_EC_PARAM_SIGNATURE = 104;
  2933. const API_EC_PARAM_TOO_MANY = 105;
  2934. const API_EC_PARAM_USER_ID = 110;
  2935. const API_EC_PARAM_USER_FIELD = 111;
  2936. const API_EC_PARAM_SOCIAL_FIELD = 112;
  2937. const API_EC_PARAM_EMAIL = 113;
  2938. const API_EC_PARAM_USER_ID_LIST = 114;
  2939. const API_EC_PARAM_FIELD_LIST = 115;
  2940. const API_EC_PARAM_ALBUM_ID = 120;
  2941. const API_EC_PARAM_PHOTO_ID = 121;
  2942. const API_EC_PARAM_FEED_PRIORITY = 130;
  2943. const API_EC_PARAM_CATEGORY = 140;
  2944. const API_EC_PARAM_SUBCATEGORY = 141;
  2945. const API_EC_PARAM_TITLE = 142;
  2946. const API_EC_PARAM_DESCRIPTION = 143;
  2947. const API_EC_PARAM_BAD_JSON = 144;
  2948. const API_EC_PARAM_BAD_EID = 150;
  2949. const API_EC_PARAM_UNKNOWN_CITY = 151;
  2950. const API_EC_PARAM_BAD_PAGE_TYPE = 152;
  2951. /*
  2952. * USER PERMISSIONS ERRORS
  2953. */
  2954. const API_EC_PERMISSION = 200;
  2955. const API_EC_PERMISSION_USER = 210;
  2956. const API_EC_PERMISSION_NO_DEVELOPERS = 211;
  2957. const API_EC_PERMISSION_ALBUM = 220;
  2958. const API_EC_PERMISSION_PHOTO = 221;
  2959. const API_EC_PERMISSION_MESSAGE = 230;
  2960. const API_EC_PERMISSION_OTHER_USER = 240;
  2961. const API_EC_PERMISSION_STATUS_UPDATE = 250;
  2962. const API_EC_PERMISSION_PHOTO_UPLOAD = 260;
  2963. const API_EC_PERMISSION_VIDEO_UPLOAD = 261;
  2964. const API_EC_PERMISSION_SMS = 270;
  2965. const API_EC_PERMISSION_CREATE_LISTING = 280;
  2966. const API_EC_PERMISSION_CREATE_NOTE = 281;
  2967. const API_EC_PERMISSION_SHARE_ITEM = 282;
  2968. const API_EC_PERMISSION_EVENT = 290;
  2969. const API_EC_PERMISSION_LARGE_FBML_TEMPLATE = 291;
  2970. const API_EC_PERMISSION_LIVEMESSAGE = 292;
  2971. const API_EC_PERMISSION_RSVP_EVENT = 299;
  2972. /*
  2973. * DATA EDIT ERRORS
  2974. */
  2975. const API_EC_EDIT = 300;
  2976. const API_EC_EDIT_USER_DATA = 310;
  2977. const API_EC_EDIT_PHOTO = 320;
  2978. const API_EC_EDIT_ALBUM_SIZE = 321;
  2979. const API_EC_EDIT_PHOTO_TAG_SUBJECT = 322;
  2980. const API_EC_EDIT_PHOTO_TAG_PHOTO = 323;
  2981. const API_EC_EDIT_PHOTO_FILE = 324;
  2982. const API_EC_EDIT_PHOTO_PENDING_LIMIT = 325;
  2983. const API_EC_EDIT_PHOTO_TAG_LIMIT = 326;
  2984. const API_EC_EDIT_ALBUM_REORDER_PHOTO_NOT_IN_ALBUM = 327;
  2985. const API_EC_EDIT_ALBUM_REORDER_TOO_FEW_PHOTOS = 328;
  2986. const API_EC_MALFORMED_MARKUP = 329;
  2987. const API_EC_EDIT_MARKUP = 330;
  2988. const API_EC_EDIT_FEED_TOO_MANY_USER_CALLS = 340;
  2989. const API_EC_EDIT_FEED_TOO_MANY_USER_ACTION_CALLS = 341;
  2990. const API_EC_EDIT_FEED_TITLE_LINK = 342;
  2991. const API_EC_EDIT_FEED_TITLE_LENGTH = 343;
  2992. const API_EC_EDIT_FEED_TITLE_NAME = 344;
  2993. const API_EC_EDIT_FEED_TITLE_BLANK = 345;
  2994. const API_EC_EDIT_FEED_BODY_LENGTH = 346;
  2995. const API_EC_EDIT_FEED_PHOTO_SRC = 347;
  2996. const API_EC_EDIT_FEED_PHOTO_LINK = 348;
  2997. const API_EC_EDIT_VIDEO_SIZE = 350;
  2998. const API_EC_EDIT_VIDEO_INVALID_FILE = 351;
  2999. const API_EC_EDIT_VIDEO_INVALID_TYPE = 352;
  3000. const API_EC_EDIT_VIDEO_FILE = 353;
  3001. const API_EC_EDIT_FEED_TITLE_ARRAY = 360;
  3002. const API_EC_EDIT_FEED_TITLE_PARAMS = 361;
  3003. const API_EC_EDIT_FEED_BODY_ARRAY = 362;
  3004. const API_EC_EDIT_FEED_BODY_PARAMS = 363;
  3005. const API_EC_EDIT_FEED_PHOTO = 364;
  3006. const API_EC_EDIT_FEED_TEMPLATE = 365;
  3007. const API_EC_EDIT_FEED_TARGET = 366;
  3008. const API_EC_EDIT_FEED_MARKUP = 367;
  3009. /**
  3010. * SESSION ERRORS
  3011. */
  3012. const API_EC_SESSION_TIMED_OUT = 450;
  3013. const API_EC_SESSION_METHOD = 451;
  3014. const API_EC_SESSION_INVALID = 452;
  3015. const API_EC_SESSION_REQUIRED = 453;
  3016. const API_EC_SESSION_REQUIRED_FOR_SECRET = 454;
  3017. const API_EC_SESSION_CANNOT_USE_SESSION_SECRET = 455;
  3018. /**
  3019. * FQL ERRORS
  3020. */
  3021. const FQL_EC_UNKNOWN_ERROR = 600;
  3022. const FQL_EC_PARSER = 601; // backwards compatibility
  3023. const FQL_EC_PARSER_ERROR = 601;
  3024. const FQL_EC_UNKNOWN_FIELD = 602;
  3025. const FQL_EC_UNKNOWN_TABLE = 603;
  3026. const FQL_EC_NOT_INDEXABLE = 604; // backwards compatibility
  3027. const FQL_EC_NO_INDEX = 604;
  3028. const FQL_EC_UNKNOWN_FUNCTION = 605;
  3029. const FQL_EC_INVALID_PARAM = 606;
  3030. const FQL_EC_INVALID_FIELD = 607;
  3031. const FQL_EC_INVALID_SESSION = 608;
  3032. const FQL_EC_UNSUPPORTED_APP_TYPE = 609;
  3033. const FQL_EC_SESSION_SECRET_NOT_ALLOWED = 610;
  3034. const FQL_EC_DEPRECATED_TABLE = 611;
  3035. const FQL_EC_EXTENDED_PERMISSION = 612;
  3036. const FQL_EC_RATE_LIMIT_EXCEEDED = 613;
  3037. const API_EC_REF_SET_FAILED = 700;
  3038. /**
  3039. * DATA STORE API ERRORS
  3040. */
  3041. const API_EC_DATA_UNKNOWN_ERROR = 800;
  3042. const API_EC_DATA_INVALID_OPERATION = 801;
  3043. const API_EC_DATA_QUOTA_EXCEEDED = 802;
  3044. const API_EC_DATA_OBJECT_NOT_FOUND = 803;
  3045. const API_EC_DATA_OBJECT_ALREADY_EXISTS = 804;
  3046. const API_EC_DATA_DATABASE_ERROR = 805;
  3047. const API_EC_DATA_CREATE_TEMPLATE_ERROR = 806;
  3048. const API_EC_DATA_TEMPLATE_EXISTS_ERROR = 807;
  3049. const API_EC_DATA_TEMPLATE_HANDLE_TOO_LONG = 808;
  3050. const API_EC_DATA_TEMPLATE_HANDLE_ALREADY_IN_USE = 809;
  3051. const API_EC_DATA_TOO_MANY_TEMPLATE_BUNDLES = 810;
  3052. const API_EC_DATA_MALFORMED_ACTION_LINK = 811;
  3053. const API_EC_DATA_TEMPLATE_USES_RESERVED_TOKEN = 812;
  3054. /*
  3055. * APPLICATION INFO ERRORS
  3056. */
  3057. const API_EC_NO_SUCH_APP = 900;
  3058. /*
  3059. * BATCH ERRORS
  3060. */
  3061. const API_EC_BATCH_TOO_MANY_ITEMS = 950;
  3062. const API_EC_BATCH_ALREADY_STARTED = 951;
  3063. const API_EC_BATCH_NOT_STARTED = 952;
  3064. const API_EC_BATCH_METHOD_NOT_ALLOWED_IN_BATCH_MODE = 953;
  3065. /*
  3066. * EVENT API ERRORS
  3067. */
  3068. const API_EC_EVENT_INVALID_TIME = 1000;
  3069. /*
  3070. * INFO BOX ERRORS
  3071. */
  3072. const API_EC_INFO_NO_INFORMATION = 1050;
  3073. const API_EC_INFO_SET_FAILED = 1051;
  3074. /*
  3075. * LIVEMESSAGE API ERRORS
  3076. */
  3077. const API_EC_LIVEMESSAGE_SEND_FAILED = 1100;
  3078. const API_EC_LIVEMESSAGE_EVENT_NAME_TOO_LONG = 1101;
  3079. const API_EC_LIVEMESSAGE_MESSAGE_TOO_LONG = 1102;
  3080. /*
  3081. * CONNECT SESSION ERRORS
  3082. */
  3083. const API_EC_CONNECT_FEED_DISABLED = 1300;
  3084. /*
  3085. * Platform tag bundles errors
  3086. */
  3087. const API_EC_TAG_BUNDLE_QUOTA = 1400;
  3088. /*
  3089. * SHARE
  3090. */
  3091. const API_EC_SHARE_BAD_URL = 1500;
  3092. /*
  3093. * NOTES
  3094. */
  3095. const API_EC_NOTE_CANNOT_MODIFY = 1600;
  3096. /*
  3097. * COMMENTS
  3098. */
  3099. const API_EC_COMMENTS_UNKNOWN = 1700;
  3100. const API_EC_COMMENTS_POST_TOO_LONG = 1701;
  3101. const API_EC_COMMENTS_DB_DOWN = 1702;
  3102. const API_EC_COMMENTS_INVALID_XID = 1703;
  3103. const API_EC_COMMENTS_INVALID_UID = 1704;
  3104. const API_EC_COMMENTS_INVALID_POST = 1705;
  3105. /**
  3106. * This array is no longer maintained; to view the description of an error
  3107. * code, please look at the message element of the API response or visit
  3108. * the developer wiki at http://wiki.developers.facebook.com/.
  3109. */
  3110. public static $api_error_descriptions = array(
  3111. self::API_EC_SUCCESS => 'Success',
  3112. self::API_EC_UNKNOWN => 'An unknown error occurred',
  3113. self::API_EC_SERVICE => 'Service temporarily unavailable',
  3114. self::API_EC_METHOD => 'Unknown method',
  3115. self::API_EC_TOO_MANY_CALLS => 'Application request limit reached',
  3116. self::API_EC_BAD_IP => 'Unauthorized source IP address',
  3117. self::API_EC_PARAM => 'Invalid parameter',
  3118. self::API_EC_PARAM_API_KEY => 'Invalid API key',
  3119. self::API_EC_PARAM_SESSION_KEY => 'Session key invalid or no longer valid',
  3120. self::API_EC_PARAM_CALL_ID => 'Call_id must be greater than previous',
  3121. self::API_EC_PARAM_SIGNATURE => 'Incorrect signature',
  3122. self::API_EC_PARAM_USER_ID => 'Invalid user id',
  3123. self::API_EC_PARAM_USER_FIELD => 'Invalid user info field',
  3124. self::API_EC_PARAM_SOCIAL_FIELD => 'Invalid user field',
  3125. self::API_EC_PARAM_USER_ID_LIST => 'Invalid user id list',
  3126. self::API_EC_PARAM_FIELD_LIST => 'Invalid field list',
  3127. self::API_EC_PARAM_ALBUM_ID => 'Invalid album id',
  3128. self::API_EC_PARAM_BAD_EID => 'Invalid eid',
  3129. self::API_EC_PARAM_UNKNOWN_CITY => 'Unknown city',
  3130. self::API_EC_PERMISSION => 'Permissions error',
  3131. self::API_EC_PERMISSION_USER => 'User not visible',
  3132. self::API_EC_PERMISSION_NO_DEVELOPERS => 'Application has no developers',
  3133. self::API_EC_PERMISSION_ALBUM => 'Album not visible',
  3134. self::API_EC_PERMISSION_PHOTO => 'Photo not visible',
  3135. self::API_EC_PERMISSION_EVENT => 'Creating and modifying events required the extended permission create_event',
  3136. self::API_EC_PERMISSION_RSVP_EVENT => 'RSVPing to events required the extended permission rsvp_event',
  3137. self::API_EC_EDIT_ALBUM_SIZE => 'Album is full',
  3138. self::FQL_EC_PARSER => 'FQL: Parser Error',
  3139. self::FQL_EC_UNKNOWN_FIELD => 'FQL: Unknown Field',
  3140. self::FQL_EC_UNKNOWN_TABLE => 'FQL: Unknown Table',
  3141. self::FQL_EC_NOT_INDEXABLE => 'FQL: Statement not indexable',
  3142. self::FQL_EC_UNKNOWN_FUNCTION => 'FQL: Attempted to call unknown function',
  3143. self::FQL_EC_INVALID_PARAM => 'FQL: Invalid parameter passed in',
  3144. self::API_EC_DATA_UNKNOWN_ERROR => 'Unknown data store API error',
  3145. self::API_EC_DATA_INVALID_OPERATION => 'Invalid operation',
  3146. self::API_EC_DATA_QUOTA_EXCEEDED => 'Data store allowable quota was exceeded',
  3147. self::API_EC_DATA_OBJECT_NOT_FOUND => 'Specified object cannot be found',
  3148. self::API_EC_DATA_OBJECT_ALREADY_EXISTS => 'Specified object already exists',
  3149. self::API_EC_DATA_DATABASE_ERROR => 'A database error occurred. Please try again',
  3150. self::API_EC_BATCH_ALREADY_STARTED => 'begin_batch already called, please make sure to call end_batch first',
  3151. self::API_EC_BATCH_NOT_STARTED => 'end_batch called before begin_batch',
  3152. self::API_EC_BATCH_METHOD_NOT_ALLOWED_IN_BATCH_MODE => 'This method is not allowed in batch mode'
  3153. );
  3154. }