0

So I found a tutorial on Facebook Login Integration at: http://www.excellencemagentoblog.com/facebook-login-integration-website

I followed it step by step and Google Chromes Developer Tools give me an error after clicking Facebook Login saying:

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

The button html is like this:

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

The script is as follows, I really can't tell what is wrong because the function is defined within the script.

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

1 回答 1

0

不太确定您在这里遇到的问题....因为即使我将其归结为带有警报的功能....它仍然无法正常工作????这意味着它与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.');
 }
 });}
于 2013-06-26T20:58:24.223 回答