开发者

How can I logout from Facebook from my application?

开发者 https://www.devze.com 2023-03-15 02:58 出处:网络
I am new to Android. I am using fbrocket example for status post for my application, but I cannot log out from my application. Status message will be posted successfully from this application, but Whe

I am new to Android. I am using fbrocket example for status post for my application, but I cannot log out from my application. Status message will be posted successfully from this application, but When I close my application, I want to also log out from Facebook.

How can i do this?

Please help me.

My code is here:

package com.drc.Incognito;

import net.xeomax.FBRocket.FBRocket;
import net.xeomax.FBRocket.LoginListener;
import net.xeomax.FBRocket.ServerErrorException;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

public class Facebook extends Activity implements LoginListener {
    private FBRocket fbRocket;

    Bundle bundle;
    int i;
    String rname,rshopno,raddress,rcity,rphone,remail,rpostcode;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Bundle bundle = getIntent().getExtras();
        rname=bundle.getString("keyshop_name");
        rshopno=bundle.getString("keyshop_no");
        raddress=bundle.getString("keystreet");
        rpostcode=bundle.getString("keypostcode");
        rcity=bundle.getString("keycity");
        rphone=bundle.getString("keyphone");
        remail=bundle.getString("keyemail");
        shareFacebook();

    }
    public void shareFacebook() {
        fbRocket = new FBRocket(this, "PitchFork TRY",
                "c3968bbdd9dc7f44a8e05b7346f46673");

        if (fbRocket.existsSavedFacebook()) {
            fbRocket.loadFacebook();
        } else {
            fbRocket.login(R.layout.main);
        }


    }
    @Override
    public void onLoginFail() {
        fbRocket.displayToast("Login failed!");
        fbRocket.login(R.layout.main);
    }
    @Override
    public void onLoginSuccess(net.xeomax.FBRocket.Facebook facebook) {
        // TODO Auto-generated method stub

        try {
            System.out.println("Incognito Shop:  " +"\n" +rname +"\n" +raddress+ "  " + rshopno +"\n" +rpostcode + " " +rcity + "\n" +rphone +"\n" + remail);
            fbRocket.displayToast("Login success!");
            facebook.setStatus("Incognito Shop:  " +"\n" +rname +"\n" +radd开发者_如何学运维ress+ "  " + rshopno +"\n" +rpostcode + " " +rcity + "\n" +rphone +"\n" + remail);

            fbRocket.displayDialog("Status Posted Successfully!! ");
        //  Intent in = new Intent(this,ShopDetail.class);
        //  startActivity(in);  
            facebook.logout();
            finish();

        } catch (ServerErrorException e) {
            if (e.notLoggedIn()) {
                fbRocket.login(R.layout.main);
            } else {
                System.out.println(e);
            }
        }

    }
}

Can you tell me how can I log out from my application when I close my application?


Actually these applications are one-click go applications, so they require username and password only once. Then these application stores them in their private files, so whenever next time the application launches, the user is logged in automatically. This facility is given since the device on which they are using are personal, so no need to logout. But if you want to log out the application, the only way is Clear the data.. Go to Settings -> Applications -> Manage Application -> Select Application -> Clear Data.


I'm pretty sure fbRocket uses the Facebook Graph API. What you must remember is that Facebook Libraries uses an Authorization protocol called OAuth. This allows the end user to login to Facebook and, when sucessful, Facebook returns an access token. This token doesn't last forever (usually, they have a TTL (Time to live)).

This token exists per application and user authentication, so if the user logs out from Facebook, the access token will expire and will be deemed obsolete.

In this regard, you don't have to worry much.

0

精彩评论

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

关注公众号