1

我正在尝试编写一个 Facebook 应用程序,一旦安装在页面上,该应用程序将提供一个简单的表单,一旦填充此表单,它将使用该用户的用户名或用户 ID 创建一个新表。

到目前为止,我已经使用外部 php 文件启动并运行 FBML 表单来处理它,我如何将用户名或用户 ID 获取到我的表单 php 操作文件。

4

1 回答 1

2

您使用的是 PHP SDK 还是 javascript SDK?如果您使用的是 PHP SDK,就这么简单:

require_once("facebook.php");

$facebook = new Facebook(array(
        'appId'  => 'YOUR_APP_ID',
        'secret' => 'YOUR_APP_SECRET',
));

$user = $facebook->getUser(); // This is the FB user ID
$username;
if ($user) {
    try {
        // Proceed knowing you have a logged in user who's authenticated.
        $user_profile = $facebook->api('/me');
        $username = $user_profile['username']; // this is the facebook username.
        // If the user hasn't set it manually, it will be something
        // like "john.doe.50"
    } catch (FacebookApiException $e) {
        error_log($e);
        $user = null;
    }
}
于 2012-05-06T16:47:02.000 回答