2013-06-26 50 views
0

所以我發現在Facebook上登錄集成教程:http://www.excellencemagentoblog.com/facebook-login-integration-websiteFacebook的登錄不定義功能

我跟着它一步一步和谷歌鉻合金開發工具給我一個錯誤點擊Facebook Login說後:

Uncaught TypeError: object is not a function index.php:53 onclick

按鈕HTML是這樣的:

<a class="btn btn-success" href='#' onclick='login();'> 
     <i class="icon-facebook"></i> 
     Facebook Login 
</a> 

該腳本如下s,我真的不知道什麼是錯的,因爲這個函數是在腳本中定義的。

<script type="text/javascript"> 

    window.fbAsyncInit = function() { 
     FB.init({ 
     appId  : ' 163289720517425', // App ID 
     channelURL : '', // Channel File, not required so leave empty 
     status  : true, // check login status 
     cookie  : true, // enable cookies to allow the server to access the session 
     oauth  : true, // enable OAuth 2.0 
     xfbml  : false // parse XFBML 
     }); 
    }; 
    // logs the user in the application and facebook 
    function login(){ 
    FB.getLoginStatus(function(r){ 
     if(r.status === 'connected'){ 
       window.location.href = 'php/fbconnect.php'; 
     }else{ 
      FB.login(function(response) { 
        if(response.authResponse) { 
        //if (response.perms) 
         window.location.href = 'php/fbconnect.php'; 
       } else { 
        // user is not logged in 
       } 
     },{scope:'email'}); // which data to access from user profile 
    } 
    }); 
    } 
    // Load the SDK Asynchronously 
    (function() { 
     var e = document.createElement('script'); e.async = true; 
     e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';     
     document.getElementById('fb-root').appendChild(e); 
    }()); 
</script> 
+0

您是否安裝了PHP SDK? – KyleK

回答

0

不太清楚您遇到此問題的....即使的Cuz當我與警報煮下來,只是功能....它仍然沒有奏效????這意味着它與Facebook無關。

反正....這是我會怎麼做....

你做跨域請求......所以你必須註冊域名....

另外.... FB提供了一個JavaScript SDK,所以不需要同時使用PHP和Javascript ...

window.fbAsyncInit = function() { 
// init the FB JS SDK 
FB.init({ 
    appId  : '163289720517425',      // App ID from the app dashboard 
    channelUrl : '//WWW.YOUR_DOMAIN.COM/channel.html', // Channel file for x-domain comms!! 
    cookie  : true, // enable cookies to allow the server to access the session 
    oauth  : true, // enable OAuth 2.0 
    status  : true,         // Check Facebook Login status 
    xfbml  : true         // Look for social plugins on the page 
}); 

// Additional initialization code such as adding Event Listeners goes here 

$('.btn-success').click(login); 

}; 

// Load the SDK asynchronously 
(function(d, s, id){ 
var js, fjs = d.getElementsByTagName(s)[0]; 
if (d.getElementById(id)) {return;} 
js = d.createElement(s); js.id = id; 
js.src = "//connect.facebook.net/en_US/all.js"; 
fjs.parentNode.insertBefore(js, fjs); 
}(document, 'script', 'facebook-jssdk')); 

function login(){ 
FB.login(function(response) { 
if (response.authResponse) { 
console.log('Welcome! Fetching your information.... '); 
FB.api('/me', function(response) { 
    console.log('Good to see you, ' + response.name + '.'); 
    }); 
} else { 
    console.log('User cancelled login or did not fully authorize.'); 
} 
});} 
+0

好的,這似乎已經使它的工作,它看起來並不像我接近完成使其功能齊全。即將用戶重定向到儀表板並將他/她的信息放入我的數據庫中。 – user2371301

+0

我在想我會等你下車。 – user2371301

+0

好吧,沒問題....我會看看我能做些什麼 – KyleK