how to integrate twitter login and facebook login

2019-08-04 00:12发布

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条回答
相关推荐>>
2楼-- · 2019-08-04 00:53

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

Step 2: Upload it in \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.

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

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

查看更多
登录 后发表回答