Giter Site home page Giter Site logo

Comments (3)

webmat avatar webmat commented on May 18, 2024

I devised a temporary fix for this. I'll explain it here, in case anyone else has that problem.

I didn't find anything in the Facebook settings I could tweak, so I tweaked the code to replace string-formatted dates by their expected integer value.

Sorry about the JavaScript, the original is written in CoffeeScript :-)

window.normalize_session_date = function(session) {
  if (typeof session.expires === 'string') {
    var M, d, h, i, m, s, y, _ref;

    _ref = (function() {
      var _i, _len, _ref, _results;
      _ref = session.expires.split(/-|:|\s/);
      _results = [];
      for (_i = 0, _len = _ref.length; _i < _len; _i++) {
        i = _ref[_i];
        _results.push(parseInt(i));
      }
      return _results;
    })();
    y = _ref[0], M = _ref[1], d = _ref[2], h = _ref[3], m = _ref[4], s = _ref[5];

    var integer_date = new Date(y, M, d, h, m, s).valueOf();
    console.log("Normalizing session.expires from '" + session.expires + "' to " + integer_date);
    session.expires = integer_date;
  }
};

Then in the main PG.FB code, I add the call to the normalization function:

    init: function(apiKey) {
        // create the fb-root element if it doesn't exist
        ...
        PhoneGap.exec(function() {
          var session = JSON.parse(localStorage.getItem('pg_fb_session') || '{"expires":0}');
          normalize_session_date(session);
          if (session.expires > new Date().valueOf()) {
            FB.Auth.setSession(session, 'connected');
            console.log("session successfully recovered");
          }
        }, null, 'com.phonegap.facebook.Connect', 'init', [apiKey]);
    },
    login: function(a, b) {
        b = b || { perms: '' };
        PhoneGap.exec(function(e) { // login
          normalize_session_date(e.session);
          localStorage.setItem('pg_fb_session', JSON.stringify(e.session));
          FB.Auth.setSession(e.session, 'connected');
          if (a) a(e);
        }, null, 'com.phonegap.facebook.Connect', 'login', b.perms.split(',') );
    },
    ...

It's a pretty nasty fix, but it works for me. I'm hoping this will help someone else until the underlying issue is fixed.

For anyone interested in the CoffeeScript version instead, here it is:

window.normalize_session_date = (session)->
  if typeof session.expires == 'string'
    [y, M, d, h, m, s] = ( parseInt(i) for i in session.expires.split(/-|:|\s/) )

    integer_date = new Date(y, M, d, h, m, s).valueOf()
    console.log("Normalizing session.expires from '" + session.expires + "' to " + integer_date)
    session.expires = integer_date

from phonegap-facebook-plugin.

kizzx2 avatar kizzx2 commented on May 18, 2024

I just filed a pull request that fixes the bug, feel free to try it :)

https://github.com/davejohnson/phonegap-plugin-facebook-connect/pull/93/files

from phonegap-facebook-plugin.

webmat avatar webmat commented on May 18, 2024

Pull request #93 works for me. Thanks @kizzx2 !

from phonegap-facebook-plugin.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.