3

一般的な JS エラー「Uncaught Reference Error: FB is not defined」が表示されます

同じ問題について多くの質問があり、stackoverflow で利用可能な各ソリューションを試しましたが、役に立ちませんでした。どうやら、人々は時々この問題を抱えているようですが、私はいつもそれを抱えています。誰でもエラーを見つけることができますか? チャンネルURLファイルは当分使っていません

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<div id="fb-root"></div>
<script type="text/javascript">
  window.fbAsyncInit = function() 
 {
    // init the FB JS SDK
    FB.init=({
      appId      : 'xxxxxxxxxxx', // App ID from the App Dashboard
      //channelUrl : 'www.something.in/channel.html', // Channel File for x-domain communication
      status     : false, // check the login status upon init?
      cookie     : true, // set sessions cookies to allow your server to access the session?
      xfbml      : true  // parse XFBML tags on this page?
      }) ;

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



</script>

<script type="text/javascript">
  // Load the SDK's source Asynchronously
  // Note that the debug version is being actively developed and might 
  // contain some type checks that are overly strict. 
  // Please report such bugs using the bugs tool.
   (function(d, debug){ 
   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" + (debug ? "/debug" : "") + ".js";
     ref.parentNode.insertBefore(js, ref);
   }(document, /*debug*/ false));



FB.getLoginStatus(function(response) {
  if (response.status === 'connected') {
    // the user is logged in and has authenticated your
    // app, and response.authResponse supplies
    // the user's ID, a valid access token, a signed
    // request, and the time the access token 
    // and signed request each expire
    var uid = response.authResponse.userID;
    var accessToken = response.authResponse.accessToken;
    alert(uid) ;
  } else if (response.status === 'not_authorized') {
    // the user is logged in to Facebook, 
    // but has not authenticated your app
    alert("not authorised");
  } else {
    // the user isn't logged in to Facebook.
    alert("NOTHING") ;
  }
 });

</script>

</body>

</html>
4

3 に答える 3

0

基本的な例を機能させることができますか? https://developers.facebook.com/docs/facebook-login/getting-started-web/ (セクション 3 の全文)

ロードするための基本的な単純な例を取得できましたが、独自のコードベース FB を含めたときに定義されませんでした。「オブジェクト」を「copyProperties」というメソッドを持つようにプロトタイプ化したという事実であることが判明しました。そのメソッドを「copyProps」に変更したところ、すべて機能するようになりました。したがって、Facebook が独自の目的で Object のプロトタイプを作成しているのであれば、他にも潜在的な衝突がいくつかあると思います。

確かに、これは誰もが Object のプロトタイプを作成しないと言う理由の 1 つに違いありませんが、とても便利です! 明らかに、それは数え切れないので、私をあまり怒鳴らないでください。

于 2013-08-02T21:43:42.790 に答える
0

私は同じ問題を抱えていて、すべてを試しました。jQueryでFacebookスクリプトをリクエストしてから初期化することで解決しました:

$(document).ready(function()
{
    $.getScript("http://connect.facebook.net/en_US/all.js#xfbml=1", function () {
        FB.init({ appId: 'xxxxxxxx', status: false, cookie: true, xfbml: true });
    });
});

FB.getLoginStatus(function(response) {
    if (response.status === 'connected') {
        // the user is logged in and has authenticated your
        // app, and response.authResponse supplies
        // the user's ID, a valid access token, a signed
        // request, and the time the access token 
        // and signed request each expire
        var uid = response.authResponse.userID;
        var accessToken = response.authResponse.accessToken;
        alert(uid) ;
    } else if (response.status === 'not_authorized') {
        // the user is logged in to Facebook, 
        // but has not authenticated your app
        alert("not authorised");
    } else {
        // the user isn't logged in to Facebook.
        alert("NOTHING") ;
    }
});
于 2017-02-21T18:58:58.837 に答える
-1

あなたのコードには に小さな誤りがあり FB.init=({ます。

FB.init の後に等号を削除する必要があり、コードは次のようになります。

FB.init({
  appId      : 'xxxxxxxxxxx', // App ID from the App Dashboard
  //channelUrl : 'www.something.in/channel.html', // Channel File for x-domain communication
  status     : false, // check the login status upon init?
  cookie     : true, // set sessions cookies to allow your server to access the session?
  xfbml      : true  // parse XFBML tags on this page?
  }) ;

あなたが犯したもう一つの間違い。あなたのdiv IDはfb-rootですが、初期化時にfacebook-jssdk IDを宣言します

両方が同じであることを確認してください

于 2013-01-02T05:15:18.927 に答える