0

我正在尝试调试一个 facebook 脚本,该脚本将用户个人资料加载到您可以编辑的表单中。

$user_profile问题是第一次加载页面时脚本不返回数组。但是,页面的后续刷新会很好地返回数组。

我怎样才能让这个数组在第一次加载页面时返回,从而让脚本的其余部分运行?这是一个AJAX解决方案,还是JSON?如果是这样,我会怎么做?

提前致谢。

<?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');

        //the below line is for debugging only - THIS PRINTS ON SCREEN REFRESH ONLY
        print_r($user_profile); 
      } 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'  => '' );

      $fqlResult = $facebook->api($param);
    }

 }
?>
4

1 回答 1

0

也许第一行有问题..

    $is_fb=false;

当页面重定向时,这是否评估为假?

如果是,那么这没有执行。

   if($is_fb) {
     //Your Code
     //Your Code   
    }
于 2012-12-20T05:37:29.220 回答