嗨,这让我疯了。在我意识到有一个Facebook特定的论坛之前,我在另一个SO论坛上发帖,但没有多少运气。很抱歉重新发帖。
我有一个访问用户个人资料的Facebook登录脚本。然后,它会重新定向并填充一个带有注册表单的页面,其中包含所有个人资料信息。
此代码跳过所有正确的箍,但问题是第一次加载页面时没有填充变量$ fqlResult,因此表单保持空白。
如果我点击f5,页面重新加载,$ fqlResult将返回正确的数据并填充表单。
<?php
$is_fb = false;
$is_linkedin = false;
$reg_method = $_GET['conn_social'];
if (isset($_GET['in_uid'])){
$cur_in_uid = $_GET['in_uid'];
}
if ($reg_method == "facebook"){
$is_fb = true;
}
else if ($reg_method == "linkedin"){
$is_linkedin = true;
}
if($is_fb) {
global $fbconfig;
$facebook = new Facebook(array( 'appId' => $fbconfig['appid'],
'secret' => $fbconfig['secret'],
'cookie' => true ));
$user = $facebook->getUser();
if ($user) {
try {
// Proceed knowing you have a logged in user who's authenticated.
$user_profile = $facebook->api('/me');
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}
$is_fb_uid_exist = hl_check_fb_uid_exist($user_profile['id']);
if($is_fb_uid_exist){
$is_fb = false;
}
try{
$fql = "select name, first_name, last_name, birthday_date, sex, profile_url, hometown_location, current_location, work, activities, interests, music, tv, movies, books, quotes, about_me, website, education, sports, inspirational_people, languages, pic_square from user where uid=" . $user;
$param = array( 'method' => 'fql.query',
'query' => $fql,
'callback' => '' );
//This is returning a blank dataset on the first page load. If you refresh the page, then the array is populated.
$fqlResult = $facebook->api($param);
}
}
?>
在此之后,每个字段都会填充一个看起来像生活的电话
<?php elseif($is_fb && isset($fqlResult[0]['first_name'])) : ?>
<input type="text" name="hl_first_name" id="hl_first_name" style="width:130px;" value="<?php echo $fqlResult[0]['first_name']; ?>" />
答案 0 :(得分:0)
在$ param中提供访问令牌,您将在第一次加载时获得结果。
$param = array( 'method' => 'fql.query',
'query' => $fql,
'access_token' => ACCESS_TOKEN,
'callback' => '' );