"; 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=
"; ?>