Saturday, December 19, 2009

pear list INSTALLED PACKAGES, CHANNEL PEAR.PHP.NET: ========================================= PACKAGE VERSION STATE Archive_Tar 1.3.3 stable Auth_SASL 1.0.3 stable Console_Getopt 1.2.3 stable DB 1.7.13 stable HTML_Template_IT 1.2.1 stable Image_GraphViz 1.2.1 stable Log 1.11.5 stable MDB2 2.4.1 stable MDB2_Driver_mysql 1.4.1 stable Mail 1.1.14 stable Net_SMTP 1.3.3 stable Net_Socket 1.0.9 stable PEAR 1.9.0 stable PEAR_Frontend_Web 0.7.4 beta Services_Facebook 0.2.8 alpha Structures_Graph 1.0.3 stable Validate 0.8.2 beta XML_Util 1.2.1 stable */ // Your exact packages may vary, especially since my test installation is a WAMP one... // Of particular note is that PEAR itself may need to be updated; use the following command to do so: // pear install --alldeps PEAR // Also note that some packages (including Services_Facebook and Validate) are either alpha or beta // These packages need to be installed while the system is in the corresponding state like: // pear config-set preferred_state beta // pear install --alldeps Validate // pear config-set preferred_state alpha // pear install --alldeps Services_Facebook // pear config-set preferred_state stable // The previous comments should serve to underscore that there are potentially a lot of things // that can go wrong with getting to the point where you can use this test code. require_once 'Services/Facebook.php'; // Set globals Services_Facebook::$apiKey = 'xxx'; Services_Facebook::$secret = 'xxx'; try { $api = new Services_Facebook(); // See: http://wiki.developers.facebook.com/index.php/Authorizing_Applications // Shows all information passed to us via get echo "Get variables:
"; print_r($_GET); echo "

"; // Shows all information passed to us via post echo "Post variables:
"; print_r($_POST); echo "

"; // Shows all variables passed to us from the server (probably not needed, but helpful) echo "Server variables:
"; print_r($_SERVER); echo "

"; // If a session key is passed, then grab it if (!empty($_POST)) { if (!empty($_POST["fb_sig_session_key"])) { $api->sessionKey = $_POST["fb_sig_session_key"]; // This next line is just for debugging echo "Obtained session key: " . $api->sessionKey . "
"; echo "This means we may use methods which require a session key.

"; } } if (!empty($_POST)) { echo "We have been given post data.
"; if (!empty($_POST["fb_sig_canvas_user"])) { $isCanvasUser = true; $uid = $_POST["fb_sig_canvas_user"]; echo "fb_sig_canvas_user says the user is a canvas user.
"; echo "Generally speaking, you won't be passed a session key, nor will you be able to
"; echo "use methods which need to be signed (so don't be surprised if you didn't get
"; echo "'fb_sig_session_key' passed to you).
"; echo "It may actually be impossible to see this message unless the surrounding FBML
"; echo "requiring that the application be authorized is removed, but this hasn't been
"; echo "tested exhaustively.
"; } else { $isCanvasUser = false; } if (!empty($_POST["fb_sig_user"])) { $isAddedUser = true; $uid = $_POST["fb_sig_user"]; echo "fb_sig_user says the user is an application user.
"; } else { $isAddedUser = false; } if ($isCanvasUser || $isAddedUser) { // We have the uid for the current user, so we can use it to get the user's friends $info = $api->users->getInfo($uid); echo "You are:
"; echo (string)$info->user->uid . ": "; echo (string)$info->user->first_name . " "; echo (string)$info->user->last_name . "

"; // A list of friend uid's, can also be gotten from $_POST but we wouldn't be able to show a call $uids = $api->friends->get($uid); $fql = 'SELECT uid, first_name, last_name FROM user WHERE uid IN (' . implode(',', $uids) . ')'; $result = $api->fql->query($fql); $friendCount = 0; echo "Here are up to twenty of your friends:
"; foreach ($result->user as $user) { if ($friendCount>=20) break; // Print only users who have authorized their data; those who have not will have empty name data if (!empty($user->first_name)&&!empty($user->last_name)) { // Print with uids //echo (string)$user->uid . ": " . (string)$user->first_name . " " . (string)$user->last_name . "
"; // Print without uids, for individual user privacy echo (string)$user->first_name . " " . (string)$user->last_name . "
"; $friendCount++; } } } } } catch (Services_Facebook_Exception $e) { echo $e->getLastCall() . "
"; echo $e->getMessage(); } echo "
The page this page is coming back to after adding is:
"; echo "http://apps.facebook.com" . $_SERVER['PHP_SELF'] . "&canvas=
"; ?>