开发者

logOut from Facebook in Android Phonegap

I have success开发者_如何学运维fully setup the Facebook Plugin by Jos located (https://github.com/jos3000/phonegap-plugins/tree/master/Android/Facebook) - but I can't seem to figure out a way to log the user out. Sure I could tell them to delete the App access on the website then try to login again and click on "Not you?" but I would really rather have a JS Function that does it for me.

Can anyone help provide some guidance on how to do this? I've looked through the files and it looks like there is a way to do it in the facebook.java but I just need to hack something together to connect it to webview. I'm not capable of doing so :) can anyone please help?


This solution is to disable the single sign on feature in the Facebook plugin

in FaceBook.java file

replace DEFAULT_AUTH_ACTIVITY_CODE in the Authorize method [2 overloads] by FORCE_DIALOG_AUTH


in FacebookAuth.Java file append this to execute method [in the switch case section]

else if (action.equals("performLogout")){
this.performLogout(first);}

//Add this method to FacebookAuth.java class

 public void performLogout(final String appid) {
    Log.d("PhoneGapLog", "LOGOUT");
    final FacebookAuth fba = this;
    Runnable runnable = new Runnable() {
        public void run() {
            fba.mFb = new Facebook(appid);
            fba.mFb.setPlugin(fba);
            try {
                fba.mFb.logout((Activity) fba.ctx);
                fba.success(new PluginResult(PluginResult.Status.OK, ""), fba.callback);
            } catch (MalformedURLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        };
    };
    this.ctx.runOnUiThread(runnable);
}

//in facebook.js file add the following section

Facebook.prototype.Logout = function(app_id,callback){
PhoneGap.exec(callback,null, "FacebookAuth", "performLogout", [app_id]); };

// in your page add the following code

function LogoutClick() //on logout click
{   
    appId = "123" ; //your app Id
    window.plugins.facebook.Logout(appId,CompleteLogout);
}   

function CompleteLogout() //call back function
{
    //do some logic for callback
}

//Enjoy..!!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜