Retrieving Facebook User Info in Flash [AS3]?

Drew

New member
I'm building my first Facebook game and I've managed to successfully create a page that retrieves user data. However, since the retrieval method requires some redirecting, when I try to load the variable in Flash it retrieves the Facebook oauth page instead of my page. So how can I get the user variables into Flash?



AS3:
var xmlLoader:URLLoader = new URLLoader();
var xmlData:XML = new XML();

xmlLoader.addEventListener(Event.COMPLETE, LoadXML);
xmlLoader.load(new URLRequest("http://mysite.com/spider/request.php"));

function LoadXML(e:Event):void {
xmlData = new XML(e.target.data);
trace(xmlData);



Request.php:
header("Content-type: text/xml");
$app_id = "xxx";
$app_secret = "xxx";
$my_url = "http://mysite.com/spider/request.php";

session_start();
$code = $_REQUEST["code"];

if(empty($code)) {
$_SESSION['state'] = md5(uniqid(rand(), TRUE)); //CSRF protection
$dialog_url = "http://www.facebook.com/dialog/oauth?client_id="
. $app_id . "&redirect_uri=" . urlencode($my_url) . "&state="
. $_SESSION['state'];
header("Location: ".$dialog_url);
}

if($_REQUEST['state'] == $_SESSION['state']) {
$token_url = "https://graph.facebook.com/oauth/access_token?"
. "client_id=" . $app_id . "&redirect_uri=" . urlencode($my_url)
. "&client_secret=" . $app_secret . "&code=" . $code;

$response = file_get_contents($token_url);
$params = null;
parse_str($response, $params);

$graph_url = "https://graph.facebook.com/me?access_token="
. $params['access_token'];

$user = json_decode(file_get_contents($graph_url),true);

$post = file_get_contents($graph_url);
echo "<id>".$user['id']."</id>";
}
 
Back
Top