您好我正在使用facebook图api PHP SDK。在这里,我试图获取登录用户的Facebook详细信息,目前我只获得不需要任何权限的基本细节。
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] => 101237886616765
[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 :(得分:1)
尝试这样做:
$url = $facebook->getLoginUrl(array('scope' => 'read_stream,friends_likes,user_birthday'));
答案 1 :(得分: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中,没有任何名为scope。还有
版本2
return $this->getUrl(
'www',
'login.php',
版本3
return $this->getUrl(
'www',
'dialog/oauth',