2011-06-21 9 views
0

私はFacebook Graph API(javascript one)を使用しています。キャンバス幅へのFB API呼び出しは常にゼロを返します

FB.Canvas.getPageInfo()["clientWidth"];関数を使用してキャンバスサイズを取得しようとしています。

しかし、いつも血まみれはゼロを返します、なぜですか?

多分私はその関数を呼び出しますか?多分ゼロになることを意図していたかもしれませんが、もしそうであれば、幅がゼロなのでキャンバス内でHTMLを見ることができないので、私はそうは思わないでしょうか?

マイコード:

<html> 
<head> 

</head> 
<body> 

    <div id="fb-root"></div> 
<script> 
    window.fbAsyncInit = function() 
     { 
     FB.init({appId: 'MYAPPID', status: true, cookie: true, xfbml: true}); 

     }; 
     (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> 
</body> 

<script type="text/javascript"> 
<!-- 
    alert(FB.Canvas.getPageInfo()["clientWidth"]); // PS other SDK calls do work likelogin so I know my app id etc are correct 
--> 
</script> 

</html> 

答えて

0

window.fbAsyncInitに割り当てられている機能は、すぐにFacebookのJS SDKがロードされている として実行されます。 SDKの後に実行するコード は、 関数内に配置し、 関数内に配置し、 FB.init()の呼び出し後に配置する必要があります。

今すぐ試してください。

<html> 
<head> 

</head> 
<body> 

<div id="fb-root"></div> 
<script> 
    window.fbAsyncInit = function() 
     { 
     FB.init({appId: 'MYAPPID', status: true, cookie: true, xfbml: true}); 
     alert(FB.Canvas.getPageInfo()["clientWidth"]); 

     }; 
     (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> 
</body> 
関連する問題