Skip to content

Instantly share code, notes, and snippets.

@niraj-shah
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save niraj-shah/0d6ec6bf80bd370dcd86 to your computer and use it in GitHub Desktop.
Save niraj-shah/0d6ec6bf80bd370dcd86 to your computer and use it in GitHub Desktop.
Creating a Facebook Page Tab App using the Facebook PHP SDK 4.0.x. This is a example how to create a likegate.
<?php
// include lines 1-65 from https://gist.github.com/niraj-shah/fcd17411def017e3aefc here
// see if the viewer has liked the page
if ( $pageHelper->isLiked() ) {
// see if we have a session
if ( isset( $session ) ) {
// show logged-in user id
echo 'User Id: ' . $pageHelper->getUserId();
// graph api request for user data
$request = new FacebookRequest( $session, 'GET', '/me' );
$response = $request->execute();
// get response
$graphObject = $response->getGraphObject()->asArray();
// print profile data
echo '<pre>' . print_r( $graphObject, 1 ) . '</pre>';
// print logout url, target = _top to break out of page frame
echo '<a href="' . $helper->getLogoutUrl( $session, 'http://sites.local/php-sdk-4.0/redirect.php' ) . '" target="_top">Logout</a>';
} else {
// show login url, target = _top to break out of page frame
echo '<a href="' . $helper->getLoginUrl( array( 'email', 'user_friends' ) ) . '" target="_top">Login</a>';
}
} else {
// show likegate
echo '<h1>Please Like the page to continue</h1>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment