简体   繁体   English

如何使用Codeigniter将Twitter登录和Facebook登录集成到网站中?

[英]how to integrate twitter login and facebook login in a web site using codeigniter?

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

Step 1: Download facebook library. 第1步:下载Facebook库。 https://github.com/facebook/facebook-php-sdk/tree/master/src https://github.com/facebook/facebook-php-sdk/tree/master/src

Step 2: Upload it in \\application\\libraries 步骤2:将其上传到\\ application \\ libraries

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. 第3步:创建一个Facebook应用程序。您将获得appId和secretcode。将以下代码粘贴到您的控制器facebook()函数中。设置appId和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);

Step 4:Paste the below code in the view page and change the appId and domain name. 步骤4:将以下代码粘贴到视图页面中,并更改appId和域名。

<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-

for more - http://www.livey.info/blog/category/php/codeigniter/ 有关更多信息-http://www.livey.info/blog/category/php/codeigniter/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM