[英]cannot get user_id with get_user()
i am using the facebook php sdk in conjunction with codeigniter. 我与codeigniter一起使用facebook php sdk。 the problem i have now is that i seem to be unable to get the user_id via get_user() it will always return 0. this is my code: 我现在遇到的问题是我似乎无法通过get_user()获得user_id,它将始终返回0。这是我的代码:
<?php
class Facebook_model extends CI_Model {
public function __construct() {
parent::__construct();
$config = array(
'appId' => '....',
'secret' => '...',
'fileUpload' => true
);
$this->load->library('facebook', $config);
$user = $this->facebook->getUser();
$profile = null;
if ($user) {
try {
$profile = $this->facebook->api('/me?fields=id,name,link,email');
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}
$fb_data = array(
'me' => $profile,
'uid' => $user,
'loginUrl' => $this->facebook->getLoginUrl(
array(
'scope' => 'email,user_birthday,publish_stream'// URL where you want to redirect your users after a successful login
)
),
'logoutUrl' => $this->facebook->getLogoutUrl()
);
$this->session->set_userdata('fb_data', $fb_data);
}
}
i read somewhere it could be a problem with cookies and codeigniter but i can't figure ou how to solve this issue 我在某处读到它可能是cookie和codeigniter的问题,但我不知道您如何解决此问题
configure your facebook configuration file as below 如下配置您的facebook配置文件
$facebook = new Facebook('keep your facebook config file here');
$my_details = $facebook->api('/me');
now the array $my_details will give you the complete details of your fb application along with the user id 现在,数组$ my_details将为您提供fb应用程序的完整详细信息以及用户ID
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.