Facebook登录未定义功能

Facebook Login Not defining Function

本文关键字:功能 未定义 登录 Facebook      更新时间:2023-09-26

所以我在http://www.excellencemagentoblog.com/facebook-login-integration-website 上找到了一个关于Facebook登录集成的教程

我一步一步地遵循它,谷歌Chromes开发者工具在点击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>

脚本如下,我真的不知道哪里出了问题,因为函数是在脚本中定义的。

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

不太确定您在这里遇到的问题。。。。因为即使我把它归结为带有警报的函数。。。。它仍然不起作用????这意味着它与脸书无关。

无论如何。。。。我会这样做…

您正在进行跨域请求。。。所以你必须注册你的域名。。。。

此外。。。。FB提供了一个JavaScriptSDK,因此不需要在尝试时同时使用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.');
 }
 });}