开发者

LogOut from Facebook using childBrowser and PhoneGap in IPhone

开发者 https://www.devze.com 2023-02-09 01:16 出处:网络
I\'m working on PhoneGap and have a FBConnect. Using childBrowser and the blog\'http://www.pushittolive.com/post/1239874936/facebook-login-on-iphone-phonegap\', I have logged in to the App. But could

I'm working on PhoneGap and have a FBConnect. Using childBrowser and the blog'http://www.pushittolive.com/post/1239874936/facebook-login-on-iphone-phonegap', I have logged in to the App. But could not logout from the app. It's autosigned in for开发者_Go百科 each time I login.

Can any one tell me how to logout from the FBConnect using Childbrowsern PhoneGap?


Try this.

Add this function to ChildBrowserCommand.m

-(void) deleteCookies:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options{
NSHTTPCookieStorage *cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage]; 
    for (NSHTTPCookie *each in [cookieStorage cookies]) {
            [cookieStorage  deleteCookie:each];
    }
}

Add this to Childbrowser.js

ChildBrowser.prototype.LogOut = function()
{
     PhoneGap.exec("ChildBrowserCommand.deleteCookies");
}

Add this to FBConnect.js

FBConnect.prototype.Logout = function()
{
   window.plugins.childBrowser.LogOut();    
}

At your page add this code to logout button on click

function Logout()
{
  var fb=FBConnect.install();
  fb.Logout();
}

Enjoy.


Best way to tell facebook to logout.

It can Be done by opening below url in child browser:

"https://www.facebook.com/logout.php?next="+your_site_url_registered _on_fb+"&access_token="+accessToken


I have struggled with this problem for ages. You may be logged on facebook but you may not have the access token so the conventional logot won't work.

By the way here's how to force the facebook logout without access token.

<!DOCTYPE html>
<html xmlns:fb="https://www.facebook.com/2008/fbml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Force facebook logout without access token</title>
</head>
<body>
    <h3>Please wait while we redirect kick you out from Facebook...</h3>
    <div id="status"></div>
    <div id="fb-root"></div>
    <script type="text/javascript">
        function spitInfo(message) {
            var infoDiv = document.getElementById("status");
            infoDiv.innerHTML += message;
            infoDiv.innerHTML += "<br/>";
        }

        window.fbAsyncInit = function () {
            spitInfo("called asyncInit");

            FB.init({
                appId: '496676837086475', //change the appId to your appId
                status: true,
                cookie: true,
                xfbml: true,
                oauth: true
            });


            function forceLogOut(response) {
                if (response.authResponse) {

                    FB.logout(function (response) {
                        spitInfo("FB.logout caller - you are logged out");
                    });
                } else {
                    spitInfo("Already logged out");
                }
            }

            // run once with current status and whenever the status changes
            FB.getLoginStatus(forceLogOut);
            FB.Event.subscribe('auth.statusChange', forceLogOut);
        };
        (function () {
            var e = document.createElement('script');
            e.async = true;
            e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
            document.getElementById('fb-root').appendChild(e);
        }());
    </script>
</body>
</html>
0

精彩评论

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