Example #1
0
function ShowLoginDialog($facebook)
{
    $facebook->setAccessToken(null);
    $cookieName = 'fbsr_' . AppConfig::GetAppId();
    setcookie($cookieName, "", 1);
    $loginUrl = $facebook->getLoginUrl(array('canvas' => 1, 'fbconnect' => 0, 'req_perms' => 'email'));
    $redirectScript = "<script type=\"text/javascript\">\n";
    $redirectScript .= "if (parent != self) \n";
    $redirectScript .= "top.location.href = \"" . $loginUrl . "\";\n";
    $redirectScript .= "else self.location.href = \"" . $loginUrl . "\";\n";
    $redirectScript .= "</script>";
    echo $redirectScript;
}
Example #2
0
/**
 * Call this function after <body> tag on each page to enable GraphAPI JavaScript SDK.
 * You can find all language codes at:
 * http://www.facebook.com/translations/FacebookLocales.xml
 */
function UseGraphAPI($languageCode = "en_US")
{
    echo "<div id='fb-root'></div>\n";
    echo "<script>\n";
    echo "var graphApiInitialized = false;\n";
    echo "  window.fbAsyncInit = function() {\n";
    echo "    FB.init({\n";
    echo "      appId  : '" . AppConfig::GetAppId() . "',\n";
    echo "      status : true, // check login status\n";
    echo "      cookie : true, // enable cookies to allow the server to access the session\n";
    echo "      xfbml  : true,  // parse XFBML\n";
    echo "      oauth: true";
    echo "    });\n";
    echo "    graphApiInitialized = true;\n";
    echo "  };\n";
    echo "  (function() {\n";
    echo "    var e = document.createElement('script');\n";
    echo "    e.src = document.location.protocol + '//connect.facebook.net/" . $languageCode . "/all.js';\n";
    echo "    e.async = true;\n";
    echo "    document.getElementById('fb-root').appendChild(e);\n";
    echo "  }());\n";
    echo "</script>\n";
}
<?php

if ($_SERVER["SERVER_NAME"] == "localhost") {
    Facebook::$CURL_OPTS[CURLOPT_SSL_VERIFYPEER] = false;
    Facebook::$CURL_OPTS[CURLOPT_SSL_VERIFYHOST] = 2;
}
require_once 'AppConfig.php';
if (AppConfig::GetAppId() == null) {
    throw new Exception("AppId key is not set. Please edit AppConfig.php file and set value from your application");
}
if (AppConfig::GetSecret() == null) {
    throw new Exception("App secret key is not set. Please edit AppConfig.php file and set value from your application");
}
if (AppConfig::GetAppName() == null) {
    throw new Exception("App name is not set. Please edit AppConfig.php file and set value from your application");
}
if (AppConfig::GetAppCanvasUrl() == null) {
    throw new Exception("App Canvas URL is not set. Please edit AppConfig.php file and set value from your application");
}
require_once 'GraphApi.php';
require_once 'LoginButton.php';
require_once 'RequestDialog.php';
require_once 'InviteFriends.php';
require_once 'InviteFriendsCondensed.php';
require_once 'StreamPublish.php';
require_once 'Permissions.php';
require_once 'LikeButton.php';
require_once 'SendButton.php';
require_once 'LikeBox.php';
require_once 'Comments.php';
require_once 'Bookmark.php';