【问题标题】:Phonegap facebook plugin: Not working when native FB app is installedPhonegap facebook 插件:安装本机 FB 应用程序时不起作用
【发布时间】:2013-07-18 12:42:15
【问题描述】:

我在 fb 插件中使用了 cordova- 2.5.0 和 facebook-sdk 3.0.2。当设备没有安装本机应用程序时,它可以正常工作。安装本机应用程序时没有发生任何事情。意味着它无法获取用户的当前访问令牌。知道吗?根据我有两种方法:

1) 像在ios 中一样禁用访问本机应用程序。但它不是正确的方式,好像用户已经在本机登录然后他必须在我的插件设置中再次登录。

2)不知道如何解决这个问题。哈希键没有问题,因为它是正确的,并且使用我的第一种方式在 ios 中运行良好。

所以我的问题是如何防止访问本机应用程序? 或者有没有其他方法可以解决这个问题?

因为我什么都没有。当我要获取用户的朋友列表时,它显示一个必须使用活动访问令牌来查询有关当前用户的信息。,"type":"OAuthException","code":2500。。 p>

cdv-pluggin-fb-connect.js

 CDV = ( typeof CDV == 'undefined' ? {} : CDV );
var cordova = window.cordova || window.Cordova;
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]);
  },
  login: function(params, cb, fail) {
    params = params || { scope: '' };
    cordova.exec(function(e) { // login
        if (e.authResponse && e.authResponse.expiresIn) {
          var expirationTime = e.authResponse.expiresIn === 0
          ? 0
          : (new Date()).getTime() + e.authResponse.expiresIn * 1000;
          e.authResponse.expirationTime = expirationTime;
        }
        localStorage.setItem('cdv_fb_session', JSON.stringify(e.authResponse));
        FB.Auth.setAuthResponse(e.authResponse, 'connected');
        if (cb) cb(e);
    }, (fail?fail:null), 'org.apache.cordova.facebook.Connect', 'login', params.scope.split(',') );
  },
  logout: function(cb, fail) {
    cordova.exec(function(e) {
      localStorage.removeItem('cdv_fb_session');
      FB.Auth.setAuthResponse(null, 'notConnected');
      if (cb) cb(e);
    }, (fail?fail:null), 'org.apache.cordova.facebook.Connect', 'logout', []);
  },
  getLoginStatus: function(cb, fail) {
    cordova.exec(function(e) {
      if (cb) cb(e);
    }, (fail?fail:null), 'org.apache.cordova.facebook.Connect', 'getLoginStatus', []);
  },
  dialog: function(params, cb, fail) {
    cordova.exec(function(e) { // login
      if (cb) cb(e);
                  }, (fail?fail:null), 'org.apache.cordova.facebook.Connect', 'showDialog', [params] );
  }
};

提前致谢!!

【问题讨论】:

    标签: android facebook cordova facebook-android-sdk


    【解决方案1】:

    我能够使用这个插件让它工作:https://github.com/jimzim/phonegap-facebook-android-sample

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-22
      • 1970-01-01
      • 1970-01-01
      • 2014-01-08
      相关资源
      最近更新 更多