2011-12-27 10 views
0

は、私は何の問題もなくchildBrowserプラグインでのFacebookにログインするために管理:ログイン、childBrowser

アプリは

function getLoginStatus() { 
FB.getLoginStatus(function(response) { 
if (response.session) { 
    alert('logged in'); 
} else { 
    alert('not logged in'); 
} 
}); 
} 

でログインしている場合、私はテスト

function deviceStart() { 

    FB.init({ appId: "xxxxxxxxxxxxxx", nativeInterface: PG.FB }); 

}; 

function onPubFacebookBtn(){ // I call this from a button 
var my_client_id = "xxxxxxxxxxxxx", 
my_redirect_uri = "http://www.facebook.com/connect/login_success.html", 
my_type   = "user_agent", 
my_display  = "touch" 

var authorize_url = "https://graph.facebook.com/oauth/authorize?"; 
authorize_url += "client_id="+my_client_id; 
authorize_url += "&redirect_uri="+my_redirect_uri; 
authorize_url += "&display="+my_display; 
authorize_url += "&scope=publish_stream,user_photos,email,user_online_presence,offline_access" 

window.plugins.childBrowser.onLocationChange = facebookLocChanged; 
window.plugins.childBrowser.onClose = closed; 
window.plugins.childBrowser.showWebPage(authorize_url); 

} 

function facebookLocChanged(loc){ 

if (/login_success/.test(loc)) { 
    var fbCode = loc.match(/code=(.*)$/)[1] 

    localStorage.setItem('pg_fb_session', JSON.stringify(fbCode)); 

    FB.Auth.setSession(fbCode, 'connected'); 
    window.plugins.childBrowser.close(); 
}} 

それ「ログイン」を返しますが、ユーザーIDを取得しようとすると、アクティブなアクセストークンが必要であるというエラーが表示されます。

function me() { 
FB.api('/me', function(response) { 
    if (response.error) { 
     alert(JSON.stringify(response.error)); 
    } else { 
     var data = document.getElementById('data'); 
      response.data.forEach(function(item) { 
      var d = document.createElement('div'); 
      d.innerHTML = item.name; 
      data.appendChild(d); 
     }); 
     } 
}); 
} 

これは2つのソリューションの混合物です。 Help !?

+0

http://stackoverflow.com/questions/16576977/is-there-any-facebook-plugin-for-phonegap-2-7-0/16579592#16579592 –

答えて

0

アクセストークンを生成するにはapplication on Facebookが必要ですが、IDを取得できますが、暗号化された形式になります。

2

Facebookのユーザー名を取得するために次のコードを使用しました。一度お試しください。

params='access_token='+accessToken; 
      $.get("https://graph.facebook.com/me",params, 
      function(response){ 
       fbUesrName=response.name; 
       },"json");