oauth script source

yazgoo edited this page Sep 14, 2010 · 11 revisions
<?
function getValue($field)
{
        $fields = split(":", $field);
        $fields = split("\"", $fields[1]);
        return $fields[1];
}
$appId="YOUR APP ID";
$secret="YOUR KEY";
$pageUri=urlencode("http://THIS PAGE URL");
if(!isset($_GET["code"]))
{
        $codeUri="https://graph.facebook.com/oauth/authorize?client_id=$appId"
                ."&redirect_uri=$pageUri&scope=offline_access,manage_pages";
        header("Location: $codeUri");
}
else
{
        $oauthUri="https://graph.facebook.com/oauth/access_token?client_id="
                ."$appId&redirect_uri=$pageUri&client_secret=$secret&code="
                .urlencode($_GET["code"])."";
        $contents = @file_get_contents($oauthUri);
        echo "<h2>Your oauth key</h2>";
        $userData = array();
        foreach(explode("&", $contents) as $variable)
        {
                $array = explode("=", $variable);
                $userData[$array[0]] = $array[1];
                echo "<b>{$array[0]}</b>: {$array[1]}</br>";
        }
        $oauthUri="https://graph.facebook.com/me/accounts?access_token="
                .urlencode($userData["access_token"]);
        $contents = @file_get_contents($oauthUri);
        preg_match("/\"name\":\"[^\"]*\"/", $contents, $names);
        preg_match("/\"access_token\":\"[^\"]*\"/", $contents, $tokens);
        echo "<h2>Your pages oauth key</h2>";
        for($i = 0; $i < count($names); $i++)
        {
                $name = getValue($names[$i]);
                $token = getValue($tokens[$i]);
                echo "<b>{$name}</b>: {$token}</br>";
        }
}
?>
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.