Skip to content

Instantly share code, notes, and snippets.

@dkd903
Last active December 15, 2015 09:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dkd903/5240490 to your computer and use it in GitHub Desktop.
Save dkd903/5240490 to your computer and use it in GitHub Desktop.
<?php
$appId = "PUT UR APP ID";
$pageName = "";
$secret = "Put YOUR APP SECRET";
$pageurl = "https://www.facebook.com/digitizormedia/app_".$appId;
$baseurl = "http://digitizormedia.com/fbapps/demos/getuseridtab/";
$redirurl = $baseurl."redir.php"; //this page redirects user back to the required tab,
//after they authorize the Facebook tab app, you cannot
//specifiy the fanpage tab url directly as the redirect URL
$installappurl = "https://www.facebook.com/dialog/pagetab?app_id=".$appId."&next=".$baseurl;
?>
<?php
include("config.php");
require 'facebook.php';
$facebook = new Facebook(array(
'appId' => $appId,
'secret' => $secret,
'cookie' => true
));
$signed_request = $facebook->getSignedRequest();
$like_status = $signed_request["page"]["liked"]; //Whether or not user has liked this page
$userFbUid = $signed_request["user_id"]; //Will have the Current User's Facebook ID if he / she has authorized the page tab app
$app_data = $signed_request["app_data"]; //this variable has additional data hich you may pass from the URL to the app
?>
<html>
<body style="margin: 0px;">
<?php
//Checks if the Facebook User ID for current user is available. If it is not available,
//it gives the option to the user to install the app
if (!isset($userFbUid)) {
?>
<?php
$authorizeUrl = "https://www.facebook.com/dialog/oauth?client_id=".$appId."&redirect_uri=".$redirurl."&scope=email";
?>
<a target="_top" href="<?=$authorizeUrl?>">Get User ID & Facebook Details</a>
<br /><br /><br /><br /><br />
<a target="_top" href="<?=$installappurl?>">Install this App on your page</a>
<?php } else {
//If data of Facebook User is available, the get his / her details
$udata = json_decode(file_get_contents("http://graph.facebook.com/".$userFbUid),TRUE); //Get user's data using Graph API
?>
Hi, <?=$udata['name'];?>
<br /><br />
<img src="http://graph.facebook.com/<?=$userFbUid?>/picture" />
<?php }
?>
<!-- Developed By Digitizor Media & Web - ricky@digitizor.com -->
<br /><br /><br />
App Tutorial: How To Get Facebook User ID, details of User in Iframe Page Tab? <a target="_blank" href="http://digitizor.com/?p=15445">http://digitizor.com/?p=15445</a>
</body>
</html>
<?php include("config.php"); ?>
<script type='text/javascript'>top.location.href='<?=$pageurl?>';</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment