首先对不起这个菜鸟问题,我正在尝试从Facebook获取数据。我已经为我的网站设置了Facebook应用程序,获取数据正在工作,但是当我将位置(Facebook信息)设置为私有时,返回的数据不包含位置数据。
这是模型
class Facebook_model extends CI_Model {
public function __construct()
{
parent::__construct();
$config = array(
'appId' => 'APP_ID',
'secret' => 'SECRET',
'fileUpload' => true,
);
$this->load->library('Facebook', $config);
$user = $this->facebook->getUser();
$profile = null;
if($user)
{
try
{
$profile = $this->facebook->api("/me", 'get');
}catch(FacebookApiException $e)
{
error_log($e);
$user = null;
}
}
$fb_data = array(
'me' => $profile,
'uid' => $user,
'loginUrl' => $this->facebook->getLoginUrl(
array(
'scope' => 'email,publish_stream,user_about_me,user_checkins,publish_stream,friends_about_me',
'redirect_uri' => base_url() . 'index.php/welcome/topsecret/'
)
),
'logoutUrl' => $this->facebook->getLogoutUrl()
);
$this->session->set_userdata('fb_data', $fb_data);
}
这是我的虚拟帐户的输出,隐私设置为公开
Array
(
[me] => Array
(
[id] => 100004160084328
[name] => Dave Batista
[first_name] => Dave
[last_name] => Batista
[link] => http://www.facebook.com/dave.batista.355
[username] => dave.batista.355
[birthday] => 08/03/1991
[hometown] => Array
(
[id] => 106050279435951
[name] => Quezon City, Philippines
)
[location] => Array
(
[id] => 106050279435951
[name] => Quezon City, Philippines
)
[gender] => male
[email] => davebatista@gmail.com
[timezone] => 8
[locale] => en_GB
[updated_time] => 2012-08-12T23:38:18+0000
)
[uid] => 100004160084328
[loginUrl] => https://www.facebook.com/dialog/oauth? client_id=266349843476112&redirect_uri=http%3A%2F%2Fpractice.com%2Findex.php%2Fwelcome%2Ftopsecret%2F&state=5d41b131b2d1e631e721cd0f6a1056aa&scope=email%2Cpublish_stream%2Cuser_about_me%2Cuser_checkins%2Cpublish_stream%2Cfriends_about_me
[logoutUrl] => https://www.facebook.com/logout.php?next=http%3A%2F%2Fpractice.com%2Findex.php%2Fwelcome%2Ftopsecret%2F&access_token=AAADyPmfObpABABJKZCZBdAXy3iPJyu4qRFEAPI8XpWS94iFZAtvnnMDkzb8yBjgQQQ8oe2O38g9QzqN834jA9axvTT0RkulRBtNItTOIAZDZD
)
尝试将"user_location"添加到$fb_data['loginUrl']['scope']。以下是您可以在FB API中使用的所有权限的列表: https://developers.facebook.com/docs/authentication/permissions/
- 在脸书应用中获取用户和朋友权限以进行user_location
-
用
$param = array('scope' =>'email,user_location,user_birthday,offline_access', 'redirect_uri' => base_url() ); 重定向($this->fb_connect->getLoginUrl($param));