Proxy > Gmail Facebook Yahoo!

Show user’s name on Facebook Application Tab page




As of now, you can show name of user (also first name, middle name, last name, username, gender and profile id) on your landing page (or on application pages) only if the user is authenticated already.
When you plan your FB application, you can consider this for the returning users. Below I am providing my full page PHP source for your reference Smile
 
$sr = parse_signed_request($_REQUEST['signed_request'], "your_app_secret_here");
 
 
$str = file_get_contents("https://graph.facebook.com/" . $sr["user_id"]);
 
 
$userarr = json_decode($str);
 
 
echo "<h3>Hello " . $userarr -> {"name"} . "</h3>";
 
echo "<hr>";
print_r($sr);
 
print_r($userarr);
 
echo "<br>Profile ID: " . $sr["user_id"];
 
 
 
function parse_signed_request($signed_request, $secret) {
  list($encoded_sig, $payload) = explode('.', $signed_request, 2); 
 
  // decode the data
  $sig = base64_url_decode($encoded_sig);
  $data = json_decode(base64_url_decode($payload), true);
 
  if (strtoupper($data['algorithm']) !== 'HMAC-SHA256') {
    error_log('Unknown algorithm. Expected HMAC-SHA256');
    return null;
  }
 
  // check sig
  $expected_sig = hash_hmac('sha256', $payload, $secret, $raw = true);
  if ($sig !== $expected_sig) {
    error_log('Bad Signed JSON signature!');
    return null;
  }
 
  return $data;
}
 
function base64_url_decode($input) {
  return base64_decode(strtr($input, '-_', '+/'));
}


Responses

0 Respones to "Show user’s name on Facebook Application Tab page"


Send mail to your Friends.  

Expert Feed

 
Return to top of page Copyright © 2011 | My Code Logic Designed by Suneel Kumar