0

我在将一个简单的变量从连接到 facebook 的 php 文件传递​​给 Flash 时遇到了一些麻烦。这就是我所做的:

当用户进入我的游戏时,他可以选择使用 facebook 登录。如果他选择这样做,我会调用一个 php 文件,将他带到 facebook,在那里他允许访问游戏,然后 facebook 将他重定向到游戏。再次进入游戏后,我使用 LoadVars 调用同一个文件,以便从 facebook 获取用户信息。由于用户已经连接到 facebook,因此变量应该正常传递给 Flash,但它们根本没有。如果我只执行 PHP,我可以正常看到变量,但它根本不会进入 Flash。

在允许访问 facebook 后,我通过将用户重定向到另一个 php 文件来解决问题。然后这个 php 文件将用户再次重定向到 flash 游戏索引,然后变量将正常传递!问题是,由于我将用户重定向到不同的 url,有时我会收到重定向错误……而且我不想使用这种方法。

有任何想法吗?

这是我的php代码:

<?php

require_once '../facebook.php'; // Require the Facebook PHP SDK

// CONNECT TO THE FACEBOOK APP
$config = array();
$config[appId] = 'xxxx';
$config[secret] = 'xxxx';
$config[fileUpload] = false;
$facebook = new Facebook ($config);

// GET THE USER ID
$user = $facebook->getUser();

if ($user) { // Succesfully got the user id. User is logged in to facebook
    $userProfile = $facebook->api('/me'); // Get the basic user info from his profile

    $toGame = "";
    $toGame .= $userProfile['first_name']."#";
    $toGame .= $userProfile['middle_name']."#";
    $toGame .= $userProfile['last_name']."#";
    $toGame .= $userProfile['birthday']."#";
    $toGame .= $userProfile['email']."#";
    $toGame .= $userProfile['gender'];

    echo $toGame;
}
else { // Failed to get the user's facebook id. Tell him to log on facebook
    $params = array ();
    $params[scope] = 'publish_stream, user_birthday, email';
    //$params[redirect_uri] = 'xxx';
    $params[redirect_uri] = 'xxx';
    $loginUrl = $facebook->getLoginUrl($params);

    echo "needLogin#".$loginUrl; // Tell Flash to redirect the user to the facebook connect page
}

?>
4

0 回答 0