PhoneGap的Facebook的插件:安装本地应用程序FB不工作时 [英] Phonegap facebook plugin: Not working when native FB app is installed

查看:113
本文介绍了PhoneGap的Facebook的插件:安装本地应用程序FB不工作时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用cordova- 2.5.0&安培; Facebook的SDK在FB 3.0.2设备没有安装本地应用程序时plugin.It工作正常。当本机应用程序安装没有什么是happened.means它不能得到user.Any想法当前访问令牌?据我的有两种方式:

I have used cordova- 2.5.0 & facebook-sdk 3.0.2 in fb plugin.It works fine when device does not have native app installed. when native app is installed nothing is happened.means it cant get current access token of user.Any idea? According to me there are two ways:

1)禁止以访问本机应用程序就像在<一个href=\"http://stackoverflow.com/questions/12327631/ios-phonegap-plugin-facebook-connect-vs-faceboook-ios-application\">ios.但它仿佛是用户登录媒体链接在本地不正确的方式,然后他要在我的插件设置重新登录。

1) disable to get access native app just like in ios. But its not right way as if user is allready login in native then he has to login again in my plugin setup.

2)不知道如何解决这个issue.There是散列键没有任何问题,因为它是正确的,用我的第一方式的ios效果很好。

2)dont know how to solve this issue.There is no issue with hash key as it is right and works well in ios using my first way.

所以我的问题是,如何prevent在访问本机应用程序? 是否有任何其他方式来解决这个问题呢?

So my question is that how to prevent to accessing native app? OR Is there any other way to solve this issue?

由于我没有得到任何东西。当我要得到用户的好友列表它给出了一个有效的访问令牌,必须使用查询有关当前用户的信息,类型:OAuthException,code:2500

As i dont get anything. when i am going to get user's friend list it shows An active access token must be used to query information about the current user.,"type":"OAuthException","code":2500.

CDV-撑着-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] );
  }
};

先谢谢了!

推荐答案

我能得到它用这个插件可以工作:的 https://github.com/jimzim/phonegap-facebook-android-sample

I was able to get it working with this plugin: https://github.com/jimzim/phonegap-facebook-android-sample

这篇关于PhoneGap的Facebook的插件:安装本地应用程序FB不工作时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆