Wednesday, January 13, 2010

PHP FBML Code Snippet: User-generated details

The below php code retrieves user data from their Facebook profile (assigning default values if the user hasn't provided the info, & spits in out in a nice, customized story.

$user_details = $facebook->api_client->users_getInfo($user_id, 'current_location, education_history, pic');
if (empty($user_details[0]['education_history'][0]['name'])){
$university = "Yale";
$graduation = "2005";
}
else
{
$university = $user_details[0]['education_history'][0]['name'];
$graduation = $user_details[0]['education_history'][0]['year'];
}
if (empty($user_details[0]['current_location']['city'])){
$city = "Poughkeepsie";
$state = "New York";
}
else
{
$city = $user_details[0]['current_location']['city'];
$state = $user_details[0]['current_location']['state'];
}
echo "
Brendan attended ";
echo $city;
echo " City College, and worked at the First Bank of ";
echo $state;

No comments:

Post a Comment