0

Problem1:When i click login button i can log in,give status.but when i press logout button it does not logout.So,how will i logout from facebook?

Problem2:I got a string str.I want to pass it in facebook's textfield (like we send messages by intent).How will i do that.

main class: `

public class MainActivity extends Activity {
private static String APP_ID = "xxxxxxx"; 

private Facebook facebook = new Facebook(APP_ID);
private AsyncFacebookRunner mAsyncRunner;
String FILENAME = "AndroidSSO_data";
private SharedPreferences mPrefs;

ImageButton btnFbLogin;
ImageButton btnFbLogout;
Button btnPostToWall;
String str="I want this to pass";

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    btnFbLogin = (ImageButton) findViewById(R.id.btn_fblogin);
    btnFbLogout = (ImageButton) findViewById(R.id.btn_fbLogout);
    btnPostToWall = (Button) findViewById(R.id.btn_fb_post_to_wall);
    mAsyncRunner = new AsyncFacebookRunner(facebook);

    btnFbLogin.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Log.d("Image Button", "button Clicked");
            loginToFacebook();
        }
    });


    btnFbLogout.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Log.d("Image Button", "button Clicked");
            logoutFromFacebook();
        }
    });

    btnPostToWall.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            postToWall();
        }
    });



}


public void loginToFacebook() {

    mPrefs = getPreferences(MODE_PRIVATE);
    String access_token = mPrefs.getString("access_token", null);
    long expires = mPrefs.getLong("access_expires", 0);

    if (access_token != null) {
        facebook.setAccessToken(access_token);

        btnFbLogin.setVisibility(View.INVISIBLE);

        btnFbLogout.setVisibility(View.VISIBLE);

        btnPostToWall.setVisibility(View.VISIBLE);



        Log.d("FB Sessions", "" + facebook.isSessionValid());
    }

    if (expires != 0) {
        facebook.setAccessExpires(expires);
    }

    if (!facebook.isSessionValid()) {
        facebook.authorize(this,
                new String[] { "email", "publish_stream" },
                new DialogListener() {

                    @Override
                    public void onCancel() {

                    }

                    @Override
                    public void onComplete(Bundle values) {
                        acess_token
                        SharedPreferences.Editor editor = mPrefs.edit();
                        editor.putString("access_token",
                                facebook.getAccessToken());
                        editor.putLong("access_expires",
                                facebook.getAccessExpires());
                        editor.commit();


                        btnFbLogin.setVisibility(View.INVISIBLE);


                        btnFbLogout.setVisibility(View.VISIBLE);


                        btnPostToWall.setVisibility(View.VISIBLE);


                    }

                    @Override
                    public void onError(DialogError error) {


                    }

                    @Override
                    public void onFacebookError(FacebookError fberror) {


                    }

                });
    }
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    facebook.authorizeCallback(requestCode, resultCode, data);
}





public void postToWall() {

    facebook.dialog(this, "feed", new DialogListener() {

        @Override
        public void onFacebookError(FacebookError e) {
        }

        @Override
        public void onError(DialogError e) {
        }

        @Override
        public void onComplete(Bundle values) {
        }

        @Override
        public void onCancel() {
        }
    });

}
public void logoutFromFacebook() {
    mAsyncRunner.logout(this, new RequestListener() {
        @Override
        public void onComplete(String response, Object state) {
            Log.d("Logout from Facebook", response);
            if (Boolean.parseBoolean(response) == true) {
                runOnUiThread(new Runnable() {

                    @Override
                    public void run() {

                        btnFbLogin.setVisibility(View.VISIBLE);


                        btnFbLogout.setVisibility(View.INVISIBLE);
                        btnPostToWall.setVisibility(View.INVISIBLE);
                    }

                });

            }
        }

        @Override
        public void onIOException(IOException e, Object state) {
        }

        @Override
        public void onFileNotFoundException(FileNotFoundException e,
                Object state) {
        }

        @Override
        public void onMalformedURLException(MalformedURLException e,
                Object state) {
        }

        @Override
        public void onFacebookError(FacebookError e, Object state) {
        }
    });
}

    }`

when i click the logout button it says: `

      08-14 14:46:59.849: D/Image Button(284): button Clicked
      08-14 14:46:59.869: D/Facebook-Util(284): GET URL: https://api.facebook.com/restserver.php? method=auth.expireSession&format=json
      08-14 14:47:00.399: D/Logout from Facebook(284): {"error_code":101,"error_msg":"Invalid application ID.","request_args":[{"key":"method","value":"auth.expireSession"},{"key":"format","value":"json"}]}

`

4

2 回答 2

0

使用它对我有用

facebook.logout(this);

在 Facebook SDK 中Facebook.java

public String logout(Context context) throws MalformedURLException, IOException {
   Util.clearCookies(context);
   Bundle b = new Bundle();
   b.putString("method", "auth.expireSession");
   String response = request(b);
   setAccessToken(null);
   setAccessExpires(0);
   return response;
}
于 2013-08-23T10:08:18.223 回答
0

只需清除 sharedprefrence 并清除 cookies 即可从 Facebook 注销

btnFbLogout.setOnClickListener(new View.OnClickListener() {

    @Override
    public void onClick(View v) {

        Log.d("Image Button", "button Clicked");
        Util.clearCookies(youractivity.this);

        // your sharedPrefrence
        Editor editor = context.getSharedPreferences("MYFB_TOKEN",    Context.MODE_PRIVATE).edit();
        editor.clear();
        editor.commit();
    }
});

或者

看到这个当我点击注销按钮时如何从 Facebook 注销

于 2013-08-14T08:01:05.310 回答