0

我有以下 HTML 表单:

<div id="online_form">
<form id="online_form_facebook" action="user_form.php" name="online_form_facebook">
<div class="field">
<div class="label">
<label for="user_email">Email:</label></div>
<div class="input">
<input id="user_email" name="user_email" readonly="readonly" type="text" value="<?php echo $user_profile['email'] ?>" /></div>
</div>

请问如何使用来自 Facebook 的用户数据填充电子邮件字段(和其他字段)?

这是我必须从 Facebook 获取值的代码:

<?
ob_start();
require_once('library/facebook.php');

$app_id = "247151652061393";
$app_secret = "123456789012345567890";

// Init facebook api.
$facebook = new Facebook(array(
    'appId' => $app_id,
    'secret' => $app_secret,
    'cookie' => false,
));

//Facebook Authentication part
$user_id = $facebook->getUser();
    $loginUrl   = $facebook->getLoginUrl(
        array(
            'scope'         => 'publish_stream,user_likes,offline_access,email,user_birthday'
        )
);

if (!$user_id) {
    echo "<script type='text/javascript'>top.location.href = '$loginUrl';</script>";
    exit;
}

?>

以上不起作用。请问如何填写这样的字段?

4

1 回答 1

0

之后您需要进行 API 调用

try
{
    $param = array (
            'method'  => 'users.getinfo',
            'uids'    => $uId,
            'fields'  => 'name , first_name , last_name , birthday , sex , email , profile_update_time , pic , pic_square , current_location , username',
            'callback'=> ''
    );
    $result = $facebook->api($param);
    var_dump($result);
}
catch(Exception $o)
{
    var_dump($o);
    exit();
}
于 2012-07-12T02:09:33.400 回答