可能重複:
php array not returning on first loadFQL查詢不在第一次加載時返回結果。只有頁面刷新後返回
你好,這是我發瘋。我發佈了另一個SO論壇之前,我意識到有一個Facebook的具體論壇,但沒有多少運氣。所以重新發佈道歉。
我有一個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']; ?>" />
是的,謝謝你。我在上面提到過。 – user1917727