2012-08-07 42 views
-1

嗨,我正在使用Facebook圖形API PHP SDK。在這裏我正在嘗試獲取登錄用戶的Facebook詳細信息,目前我只能獲取不需要任何權限的基本信息。請求用戶權限不工作Facebook圖形API

Array 
(
    [id] => xxxxxxxxx 
    [name] => Kanishka Bandara Panamaldeniya 
    [first_name] => Kanishka 
    [middle_name] => Bandara 
    [last_name] => Panamaldeniya 
    [link] => http://www.facebook.com/kanishka.panamaldeniya 
    [username] => kanishka.panamaldeniya 
    [hometown] => Array 
     (
      [id] => 108014839219027 
      [name] => Kandy 
     ) 

    [location] => Array 
     (
      [id] => 108602292505393 
      [name] => Colombo, Sri Lanka 
     ) 

    [quotes] => every action has a reaction.... 
    [work] => Array 
     (
      [0] => Array 
       (
        [employer] => Array 
         (
          [id] => 234117399957729 
          [name] => Cyber LMJ 
         ) 

        [location] => Array 
         (
          [id] => 108602292505393 
          [name] => Colombo, Sri Lanka 
         ) 

        [position] => Array 
         (
          [id] => 109542932398298 
          [name] => Software Engineer 
         ) 

        [start_date] => 2011-08 
       ) 

      [1] => Array 
       (
        [employer] => Array 
         (
          [id] => 235852306375 
          [name] => eMarketingEye 
         ) 

        [position] => Array 
         (
          [id] => 109542932398298 
          [name] => Software Engineer 
         ) 

        [start_date] => 2010-09 
        [end_date] => 2011-08 
       ) 

     ) 

    [sports] => Array 
     (
      [0] => Array 
       (
        [id] => 103992339636529 
        [name] => Cricket 
       ) 

     ) 

    [favorite_teams] => Array 
     (
      [0] => Array 
       (
        [id] => 191485640872790 
        [name] => Sri Lanka Cricket Team 
       ) 

     ) 

    [favorite_athletes] => Array 
     (
      [0] => Array 
       (
        [id] => 185101794860886 
        [name] => Kumara Sangakkara 
       ) 

      [1] => Array 
       (
        [id] => 119473804782315 
        [name] => Angelo Mathews 
       ) 

      [2] => Array 
       (
        [id] => 164574093575397 
        [name] => Kumar Sangakkara 
       ) 

      [3] => Array 
       (
        [id] => 169411436417102 
        [name] => Virat Kohli 
       ) 

      [4] => Array 
       (
        [id] => 166273026737204 
        [name] => Lahiru Thirimanne 
       ) 

      [5] => Array 
       (
        [id] => 1
        [name] => Dinesh Chandimal 
       ) 

     ) 

    [education] => Array 
     (
      [0] => Array 
       (
        [school] => Array 
         (
          [id] => 34663330581 
          [name] => Dharmaraja College-Kandy 
         ) 

        [year] => Array 
         (
          [id] => 138383069535219 
          [name] => 2005 
         ) 

        [type] => High School 
       ) 

      [1] => Array 
       (
        [school] => Array 
         (
          [id] => 112872282058324 
          [name] => University of Colombo School of Computing 
         ) 

        [year] => Array 
         (
          [id] => 140617569303679 
          [name] => 2007 
         ) 

        [type] => College 
       ) 

      [2] => Array 
       (
        [school] => Array 
         (
          [id] => 107577089271805 
          [name] => University of Colombo 
         ) 

        [type] => Graduate School 
        [with] => Array 
         (
          [0] => Array 
           (
            [id] => 705760115 
            [name] => Lasitha Benaragama 
           ) 

         ) 

       ) 

     ) 

    [gender] => male 
    [timezone] => 5.5 
    [locale] => en_US 
    [languages] => Array 
     (
      [0] => Array 
       (
        [id] => 104023029632921 
        [name] => Sinhala 
       ) 

      [1] => Array 
       (
        [id] => 106059522759137 
        [name] => English 
       ) 

     ) 

    [verified] => 1 
    [updated_time] => 2012-07-29T16:34:22+0000 
) 

現在我想田

*email 
*birth day 

和其他一些許可請求領域。

,所以我做

$this->co_config_items = $this->ci->config->item('connections_config'); 
    $fbconfig = array(
    'appId' => $this->co_config_items['fb_appid'], 
    'secret' => $this->co_config_items['fb_secret'], 
    'cookie' => true, 
    'domain' => $this->ci->config->item('domain') 
    ); 

    $this->ci->load->library('3rd/connectors/facebook', $fbconfig); 

    $facebook = new Facebook($fbconfig); 
    Facebook::$CURL_OPTS[CURLOPT_SSL_VERIFYPEER] = false; 
    Facebook::$CURL_OPTS[CURLOPT_SSL_VERIFYHOST] = 2; 

    $session = $facebook->getSession(); 

    $url = $facebook->getLoginUrl(array(
        'canvas' => 1, 
        'fbconnect' => 0, 
        'scope' => 'read_stream,friends_likes,user_birthday' 
    ));  

    if(!$session){ 
     $url = $facebook->getLoginUrl(array(
        'canvas' => 1, 
        'fbconnect' => 0, 
        'scope' => 'read_stream,friends_likes,user_birthday' 

       )); 

     echo "<script type='text/javascript'>window.location = '$url';</script>"; 
    } 
    else{ 
     //echo "<script type='text/javascript'>window.opener.location.href='" . base_url() . "home/auth/get_user_facebook_details_list" . "'; self.close(); 
     //</script>"; 
     try { 

      $me = $facebook->api('/me'); 

      $this->ci->session->set_flashdata ('user_details',$me); 
      $url=base_url()."home/auth/user_contact_information";    
      echo "<script type='text/javascript'>window.opener.location.href = '$url';self.close();</script>"; 

     } catch (FacebookApiException $e) { 
      $this->ci->message->set_error(array('An errror occured , please try again')); 
     } 
    } 

我試圖問權限由

 $url = $facebook->getLoginUrl(array(
         'canvas' => 1, 
         'fbconnect' => 0, 
         'scope' => 'read_stream,friends_likes,user_birthday' 
)): 

但它不要求任何權限,默認數組總是打印。這是爲什麼 。請幫忙 。在此先感謝

回答

0

我使用PHP SDK的版本2,我現在用的第3版,現在它的工作,非常感謝你。我看到了兩個版本的一些變化,這個功能

版本2

public function getLoginUrl($params=array()) { 
     $currentUrl = $this->getCurrentUrl(); 
     return $this->getUrl(
       'www', 
       'login.php', 
       array_merge(array(
        'api_key' => $this->getAppId(), 
        'cancel_url' => $currentUrl, 
        'display' => 'page', 
        'fbconnect' => 1, 
        'next' => $currentUrl, 
        'return_session' => 1, 
        'session_version' => 3, 
        'v' => '1.0', 
         ), $params) 
     ); 
    } 

版本3

public function getLoginUrl($params=array()) { 
    $this->establishCSRFTokenState(); 
    $currentUrl = $this->getCurrentUrl(); 

    // if 'scope' is passed as an array, convert to comma separated list 
    $scopeParams = isset($params['scope']) ? $params['scope'] : null; 
    if ($scopeParams && is_array($scopeParams)) { 
     $params['scope'] = implode(',', $scopeParams); 
    } 

    return $this->getUrl(
     'www', 
     'dialog/oauth', 
     array_merge(array(
        'client_id' => $this->getAppId(), 
        'redirect_uri' => $currentUrl, // possibly overwritten 
        'state' => $this->state), 
        $params)); 
    } 

在3這個版本我可以看到這個額外的代碼在

// if 'scope' is passed as an array, convert to comma separated list 
    $scopeParams = isset($params['scope']) ? $params['scope'] : null; 
    if ($scopeParams && is_array($scopeParams)) { 
     $params['scope'] = implode(',', $scopeParams); 
    } 

版本2,沒有什麼叫範圍,並且還有

在版本2

return $this->getUrl(
        'www', 
        'login.php', 

在版本3

return $this->getUrl(
      'www', 
      'dialog/oauth', 
1

儘量不要做這樣的:

$url = $facebook->getLoginUrl(array('scope' => 'read_stream,friends_likes,user_birthday'));