[英]Login with facebook in codeigniter
I am using this, for login with Facebook , but i am not getting user response here is the link 我使用这个,用于登录Facebook ,但我没有得到用户响应这里是链接
http://demos.idiotminds.com/link.php?link=https://www.box.com/s/108pspt0o0oj0fpr6ghf http://demos.idiotminds.com/link.php?link=https://www.box.com/s/108pspt0o0oj0fpr6ghf
I have tried this solution also for codeigniter 我曾尝试这种解决方案也为笨
protected function getCode() {
$server_info = array_merge($_GET, $_POST, $_COOKIE);
if (isset($server_info['code'])) {
if ($this->state !== null &&
isset($server_info['state']) &&
$this->state === $server_info['state']) {
// CSRF state has done its job, so clear it
$this->state = null;
$this->clearPersistentData('state');
return $server_info['code'];
} else {
self::errorLog('CSRF state token does not match one provided.');
return false;
}
}
return false;
}
for log in with Facebook but i am not getting value from this $user = $facebook->getUser();
用Facebook登录,但我没有从这个
$user = $facebook->getUser();
获得价值$user = $facebook->getUser();
it returns 0 value even if i have logged into Facebook. 即使我已登录Facebook,它也会返回0值。 I have used so many codes for this but did not success, kindly help me out.
我已经使用了这么多代码,但没有成功,请帮助我。 I am very frustrated
我很沮丧
Download PHP SDK for Facebook 下载适用于Facebook的PHP SDK
Now create the a folder in application\\libarires "facebook" 现在在application \\ libarires“facebook”中创建一个文件夹
Put the "SRC" folder of PHP SDK 放置PHP SDK的“SRC”文件夹
Now create a file with FacebookApp.php in that folder and put this code 现在在该文件夹中创建一个带有FacebookApp.php的文件并放入此代码
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
require_once( APPPATH . 'libraries/facebook/src/facebook.php' );
class FacebookApp extends Facebook {
var $ci;
var $facebook;
var $scope;
public function __construct() {
$this->ci =& get_instance();
$this->facebook = new Facebook(array('appId' => $this->ci->config- >item('app_id'),'secret' => $this->ci->config->item('app_secret'), 'cookie' => true));
$this->scope = 'public_profile';
}
public function login_url() {
$params = array('scope' => $this->scope);
return $this->facebook->getLoginUrl($params);
}
public function logout_url() {
return $this->facebook->getLogoutUrl(array('next' => base_url() .'logout'));
}
public function getFbObj(){
return $this->facebook;
}
public function get_user() {
$data = array();
$data['fb_user'] = $this->facebook->getUser();
if ($data['fb_user']) {
try {
$data['fb_user_profile'] = $this->facebook->api('/me');
return $data;
} catch (FacebookApiException $e) {
$this->facebook->destroySession();
$fb_login_url = $this->facebook->getLoginUrl(array('scope' => $this->scope));
redirect($fb_login_url, 'refresh');
}
}
}
Now in controller load this library $this->load->library('facebook/FacebookApp)
现在在控制器中加载这个库
$this->load->library('facebook/FacebookApp)
in Method 在方法中
$obj_fb = new FacebookApp(); $fb_user_data = $obj_fb->get_user(); $data['fb_login_url'] = $obj_fb->login_url();
put the fb_login_url in href of login button and now the login will done. 把fb_login_url放在登录按钮的href中,现在登录就完成了。
Hope it help you. 希望它对你有所帮助。
Rahul, I had a similar issue. 拉胡尔,我有类似的问题。 You can find a pretty good solution here .
你可以在这里找到一个很好的解决方案。
If you still cannot figure the solution, why don't you look into the JavaScript SDK . 如果您仍然无法找到解决方案,为什么不查看JavaScript SDK 。 It is pretty straight forward and then use AJAX to act on the response that you get from Facebook.
它很直接,然后使用AJAX来处理你从Facebook获得的响应。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.