2012-09-22 166 views
0

我正在使用CS購物車電子商務系統,並且我已經瀏覽了Facebook和其他各種網站上的所有教程,以便將facebook集成到我的網站。意思是,我在我的網站上有標準的用戶註冊。然而,我正在尋找實現登錄Facebook的按鈕,其中一個Facebook用戶將能夠登錄使用他的Facebook的憑據。我也被要求參考https://github.com/facebook/facebook-php-sdk用FB按鈕登錄

我不是一個程序員來理解這一點。如果有人能幫上忙,那會很好。

在此先感謝。

回答

2

爲您需要創建app in the facebook比你需要的AppKey和分泌

enter image description here

,並設置URL確保該網站的網址是,你必須在同一頁上登錄按鈕並且不能在同一個應用程序的多個地方登錄按鈕

enter image description here

和下面的腳本

<?php 

define('YOUR_APP_ID', 'YOUR APP ID'); 

//uses the PHP SDK. Download from https://github.com/facebook/php-sdk 
require 'facebook.php'; 

$facebook = new Facebook(array(
    'appId' => YOUR_APP_ID, 
    'secret' => 'YOUR APP SECRET', 
)); 

$userId = $facebook->getUser(); 

?> 

<html> 
    <body> 
    <div id="fb-root"></div> 
    <?php if ($userId) { 
     $userInfo = $facebook->api('/' . $userId); ?> 
     Welcome <?= $userInfo['name'] ?> 
    <?php } else { ?> 
    <fb:login-button></fb:login-button> 
    <?php } ?> 


     <div id="fb-root"></div> 
     <script> 
      window.fbAsyncInit = function() { 
      FB.init({ 
       appId  : 'YOUR_APP_ID', // App ID 
       channelUrl : '//WWW.YOUR_DOMAIN.COM/channel.html', // Channel File 
       status  : true, // check login status 
       cookie  : true, // enable cookies to allow the server to access the session 
       xfbml  : true // parse XFBML 
      }); 
     FB.Event.subscribe('auth.login', function(response) { 
      window.location.reload(); 
     }); 
      }; 
      // Load the SDK Asynchronously 
      (function(d){ 
      var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0]; 
      if (d.getElementById(id)) {return;} 
      js = d.createElement('script'); js.id = id; js.async = true; 
      js.src = "//connect.facebook.net/en_US/all.js"; 
      ref.parentNode.insertBefore(js, ref); 
      }(document)); 
     </script> 

    </body> 
</html> 

你可以在Facebook for Websites

看到完整的文檔和教程