Facebook Javascript SDK error "Object [object Object] has no method 'init` -
one of first things needs done in order load sdk interacting facebook, run:
fb.init(params)
this method used initialize , setup sdk. . . . . . other sdk methods must called after one, because won't exist until do.
facebook javascript sdk: .init()
i'm getting error msg:
object [object object] has no method "init"
i'm not getting error fb
undefined, i'm assuming @ least part of facebook javascript sdk
loaded.
when sdk
loads, facebook puts contents <div>
element: <div id="fb-root"></div>
just fun of it, used .innerhtml
see if extract out of <div>
.
var fbrootcontent = document.getelementbyid('fb-root').innerhtml; console.log("fbroot content: " + fbrootcontent);
and show got injected <div>
. so, . . . i'm assuming @ least of facebook javascript sdk
loaded.
one possible issue, i'm using google apps script, , lots of content gets sanitized , stripped out before served. it's possibility that, though of sdk loading, of getting stripped out sanitation process.
i'm trying determine if it's possible load facebook javascript sdk
apps script. haven't had luck far. here latest code i've used in attempt test whether sdk can loaded or not.
<div id="fb-root"></div> <label id="lbltohid">load facebook javascript sdk</label> <br> <br> <button id="btntest">test</button> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script> <script src="https://connect.facebook.net/en_us/all.js"></script> <script> $(document).ready(function() { $("#lbltohid").hide(); $("#btntest").click(function(){ $("#lbltohid").show(); }); callfb(); fbasyncinit(); }); function callfb(){ console.log("callfb ran: "); window.fbasyncinit = function() { console.log("asyncinit ran"); console.log("here object fb: " + fb); var fbrootcontent = document.getelementbyid('fb-root').innerhtml; console.log("fbroot content: " + fbrootcontent); fb.init({ appid : 'myappid here', status : true, // check login status cookie : true, // enable cookies allow server access session oauth : true, // enable oauth 2.0 xfbml : true // parse xfbml }); console.log("callfb done running: "); }; }; </script>
note not loading sdk asynchronously. i'm doing on purpose test if load or not. note line:
<script src="https://connect.facebook.net/en_us/all.js"></script>
facebook suggests loading sdk different way. why? because might slow down initial load of app.
so, why getting error: object [object object] has no method "init"
and possible load facebook javascript sdk
google apps script?
i'm using jquery: $(document).ready
,
so fb.init
shouldn't getting called until <script>
tag has loaded facebook sdk.
try changing facebook script import this.
<script src="//connect.facebook.net/en_us/all.js#xfbml=1&appid={your-app-id}"></script>
where {your-app-id} actual app id.
update
have tried this.
function callfb(){ console.log("callfb ran: "); window.fbasyncinit = function() { console.log("asyncinit ran"); fb.init({ appid : 'myappid here', status : true, // check login status cookie : true, // enable cookies allow server access session oauth : true, // enable oauth 2.0 xfbml : true // parse xfbml }); console.log("here object fb: " + fb); var fbrootcontent = document.getelementbyid('fb-root').innerhtml; console.log("fbroot content: " + fbrootcontent); console.log("callfb done running: "); }; };
Comments
Post a Comment