Wizcorp / phonegap-facebook-plugin

The official plugin for Facebook in Apache Cordova/PhoneGap
Other
1.9k stars 2.01k forks source link

Init( ); TypeError? #135

Closed lumierephoto closed 12 years ago

lumierephoto commented 12 years ago

I'm getting a pop-up alert upon init(); of my app:

                          index.html
        TypeError: 'null' is not an object

The plugin works fine on Cordova 1.6.1, iOS 5.1(iPad2 Device) and Xcode 4.3.2

My guess is that it's coming from somewhere here in the 'cdv-plugin-fb-connect.js':

       CDV.FB = {
         init: function(apiKey, fail) {
         // create the fb-root element if it doesn't exist
         if (!document.getElementById('fb-root')) {
         var elem = document.createElement('div');
         elem.id = 'fb-root';
         document.body.appendChild(elem);
       }
       cordova.exec(function() {
          var authResponse = JSON.parse(localStorage.getItem('cdv_fb_session') || '{"expiresIn":0}');
        if (authResponse && authResponse.expirationTime) { 
           var nowTime = (new Date()).getTime();
        if (authResponse.expirationTime > nowTime) { 
         // Update expires in information
        updatedExpiresIn = Math.floor((authResponse.expirationTime - nowTime) / 1000);
        authResponse.expiresIn = updatedExpiresIn;

         localStorage.setItem('cdv_fb_session', JSON.stringify(authResponse));
         FB.Auth.setAuthResponse(authResponse, 'connected');
         }
      }
         console.log('Cordova Facebook Connect plugin initialized successfully.');
         }, (fail?fail:null), 'org.apache.cordova.facebook.Connect', 'init', [apiKey]);
      },

I also notice that in the 'Facebook_js_sdk.js' the api key is 'null' which corresponds to '(fail?fail:null), 'org.apache.cordova.facebook.Connect', 'init', [apiKey])' in the above script:

        if (!window.FB) {
           window.FB = {
        // use the init method to set these values correctly
         _apiKey       : null,
         _authResponse : null,
         _userStatus   : 'unknown', // or 'notConnected' or 'connected

Anyone else have this problem?

Also, I'm not using the id: 'fb-root' in my HTML. I firing off the 'facebookWallPost()' in an action sheet button. Everything works great, I'm just trying to fix this error!

lumierephoto commented 12 years ago

I solved this issue by adding these ID's from the example into the HTML. Leaving them empty:

        <div id="data"></div>
        <div id="fb-root"></div>
        <div id="log"></div>