PageRenderTime 69ms CodeModel.GetById 29ms RepoModel.GetById 0ms 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

Large files files are truncated, but you can click here to view the full file

  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 …

Large files files are truncated, but you can click here to view the full file