2013-05-27 102 views

回答

2

第1步:下載Facebook庫https://github.com/facebook/facebook-php-sdk/tree/master/src

第2步:上傳它在\程序\庫

第3步:創建一個Facebook application.You WIL得到appId和secretcode.Paste在你的控制器的facebook()函數下面的代碼。設置appId和祕密。

$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和域名。

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

+0

感謝ü這麼多Jerin我會嘗試一下:) – Mhansi

+1

感謝ü這麼多它的工作:) :)需要幫助Twitter的登錄 – Mhansi

+1

嘗試在google..I有隻有Facebook的現成的代碼..一旦你拿到代碼,就把它放在這裏。嘗試 –