意外的令牌错误

时间:2012-12-18 12:53:25

标签: facebook facebook-graph-api facebook-javascript-sdk

我正在尝试使用Facebook登录帮助指南来整理脚本以检查用户是否已登录。我已根据this guide汇总了以下内容。

<div id="fb-root"></div>
<script>
  // Additional JS functions here
  window.fbAsyncInit = function() {
    FB.init({
      appId      : '303594953085775', // App ID
      channelUrl : 'http://mysite.com/pages/account/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
    });

    // Additional init code here
    FB.getLoginStatus(function(response) {
    if (response.status === 'connected') {
        // connected
    } else if (response.status === 'not_authorized') {
        // not_authorized
        login();
    } else {
        // not_logged_in
        login();
    }
    });
    };

  };

  function login() {
    FB.login(function(response) {
        if (response.authResponse) {
            // connected
            testAPI();
        } else {
            // cancelled
        }
    });
    }

    function testAPI() {
    console.log('Welcome!  Fetching your information.... ');
    FB.api('/me', function(response) {
        console.log('Good to see you, ' + response.name + '.');
    });
    }

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

我完全复制它时,我不知道我做错了什么。我已经复制了四次,但它仍然会出现错误,尽管它完全在Facebook网站上写的是什么。

我收到两个错误:

Uncaught SyntaxError: Unexpected token }

Uncaught SyntaxError: Unexpected token .

我对这种复杂的JavaScript并不了解,因为我只知道如何做一些基本的调用和事情,这目前让我想要把自己从建筑物里扔掉。

有谁能告诉我为什么会出错? 是否有某个地方我可以抓住整个正确的脚本并替换我的应用ID和域名,而不必通过这个愚蠢的Facebook指南?

2 个答案:

答案 0 :(得分:1)

代码中存在语法错误:

window.fbAsyncInit = function() {
  FB.init({
    appId      : '303594953085775', // App ID
    channelUrl : 'http://mysite.com/pages/account/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
  });

  // Additional init code here
  FB.getLoginStatus(function(response) {
  if (response.status === 'connected') {
      // connected
  } else if (response.status === 'not_authorized') {
      // not_authorized
      login();
  } else {
      // not_logged_in
      login();
  }
  });

};
};        **// REMOVE THIS- This one is extra**

您可以使用Notepad ++或任何其他好的编辑器来避免此类错误:)

答案 1 :(得分:0)

我有同样的问题,这是由直接复制和粘贴代码引起的,它以某种方式将一些奇怪的字符放在那里。我通过物理重写来修复它,而不是直接复制和粘贴。

相关问题