FB API call to canvas width always gives zero
I am using the Facebook Graph API (javascript one).
I am trying to get the canvas size using the function FB.Canvas.getPageInfo()["clientWidth"];
But it always bloody returns zero, why?
Maybe its when I call the function? Maybe its meant to be zero, but I dont think so because i开发者_运维技巧f it was I would not be able to see my HTML inside the canvas because the width is zero right?
My code:
<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>
the function assigned to window.fbAsyncInit is run as soon as the Facebook JS SDK is loaded. Any code you want to run after the SDK is loaded should be placed within this function and after the call to FB.init().
now try this.
<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>
精彩评论