如何使用Codeigniter将Twitter登录和Facebook登录集成到网站中? [英] how to integrate twitter login and facebook login in a web site using codeigniter?

查看:77
本文介绍了如何使用Codeigniter将Twitter登录和Facebook登录集成到网站中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用twitter oauth和facebook库登录到我的网站了。在它无法正常工作之前它可以正常工作:(。我调试了代码,并且知道twitter访问令牌和密码没有返回。 Facebook登录也没有得到用户id.pls帮助

I have already used twitter oauth and facebook library to login to my website.It works fine before now it is not working :(.I have debug the code and got to know that twitter access token and secret is not returning.For facebook login it also didnt get user id.pls help

推荐答案

步骤1:下载facebook库。 https://github.com/facebook/facebook-php-sdk/tree/master/src

Step 1: Download facebook library.https://github.com/facebook/facebook-php-sdk/tree/master/src

第2步:在\application

Step 2: Upload it in \application\libraries

第3步:创建一个Facebook应用程序您将获得appId和secretcode。将以下代码粘贴到控制器facebook()函数中。设置appId和secret。

Step 3:Create a facebook application.You wil get appId and secretcode.Paste the below code in your controller facebook() function.Set the appId and secret.

$config = array(
'appId' => '234353465466',
'secret' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx',
'fileUpload' => true, // Indicates if the CURL based @ syntax for file uploads is enabled.
);
$this->load->library('Facebook',$config);

$user = $this->facebook->getUser();
if($user){
try {
$profile = $this->facebook->api('/me?fields=id,name,link,email');
}
catch (FacebookApiException $e) {
$user = null;
}
echo '<pre>';
print_r($profile);

第4步:将以下代码粘贴到视图页面中,并更改appId和域名。

Step 4:Paste the below code in the view page and change the appId and domain name.

<div id="fb-root"></div>
<script type="text/javascript">// <![CDATA[
window.fbAsyncInit = function() {
FB.init({appId: '234463456', status: true, cookie: true,xfbml: true,oauth: true});};
(function() {
var e = document.createElement('script');
e.type = 'text/javascript';
e.src = document.location.protocol+'//connect.facebook.net/en_GB/all.js';
e.async = true;
document.getElementById('fb-root').appendChild(e);
}());
function login()
{
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
document.location.href = "http://www.mydomain.com/facebook?accessToken="+response.authResponse.accessToken;
}
});
}
// ]]></script> 
  <fb:login-button scope="email" onlogin="login();" >Sign in with Facebook</fb:login-

了解更多- http://www.livey.info/blog/category/php/codeigniter/

这篇关于如何使用Codeigniter将Twitter登录和Facebook登录集成到网站中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆