Creating a Facebook Page Tab App using the Facebook PHP SDK 4.0.x. This is a example how to create a likegate.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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