Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.