登录与Android,的PhoneGap至Facebook,childBrowser
问题描述:
我设法登录到Facebook上与childBrowser插件没有任何问题:登录与Android,的PhoneGap至Facebook,childBrowser
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();
}}
当我测试,如果应用程序与
function getLoginStatus() {
FB.getLoginStatus(function(response) {
if (response.session) {
alert('logged in');
} else {
alert('not logged in');
}
});
}
登录它返回“loged in”,但是当我尝试获取用户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);
});
}
});
}
这是两种解决方案的混合体,用于登录到其中没有任何作品的Facebook。 帮助!?
答
我已经使用下面的代码来获取Facebook用户的名字,请尝试一次。
params='access_token='+accessToken;
$.get("https://graph.facebook.com/me",params,
function(response){
fbUesrName=response.name;
},"json");
http://*.com/questions/16576977/is-there-any-facebook-plugin-for-phonegap-2-7-0/16579592#16579592 – 2013-06-11 03:52:39