适用于 Android 的 Facebook SDK 4 - 如何以编程方式注销 [英] Facebook SDK 4 for Android - how to log out programmatically

查看:26
本文介绍了适用于 Android 的 Facebook SDK 4 - 如何以编程方式注销的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近,Facebook 发布了带有新的酷炫更新的 SDK 4.我尝试切换到 SDK4 以使用新功能,但是,我在 Facebook 的登录功能方面遇到了困难.

Recently, Facebook released SDK 4 with new and cool updates. I tried to switch into SDK4 to use new features, however, I am struggling with the Login feature of Facebook.

到目前为止,为了以编程方式注销 Facebook,我使用了:

So far, to log out Facebook programmatically, I used :

Session session = Session.getActiveSession();
session.closeAndClearTokenInformation();

但 SDK4 似乎不再支持 Session,并且在官方文档中,他们提到:

But SDK4 seems not to support Session anymore, and in official docs, they mention:

有两种方法可以在 Android 上实现 Facebook 登录:

There are two ways to implement Facebook login on Android:

LoginButton 类 - 提供可以添加到 UI 的按钮.它遵循当前的访问令牌,可以让人们登录和退出.

LoginButton class - Which provides a button you can add to your UI. It follows the current access token and can log people in and out.

好吧,除了使用 LoginButton 之外,似乎没有办法以编程方式注销 Facebook.任何人有任何想法,请在这里分享.

Well, seems there's no way to log out Facebook programmatically except using LoginButton. Anyone have any idea, please share it here.

推荐答案

你可以使用 LoginManager.getInstance().logOut();,即使你使用 LoginButton 因为

You can use LoginManager.getInstance().logOut();, even if you use LoginButton because

此 UI 元素包装了 LoginManager 中可用的功能.

This UI element wraps functionality available in the LoginManager.

顺便提一下,这适用于 Facebook SDK v4.不知道以后会不会改.

Just to mention that this works for Facebook SDK v4. I don't know if they will change it in the future.

@as batoutofhell 提到,不要忘记把 FacebookSdk.sdkInitialize(getApplicationContext()); 初始化 facebook sdk.请参阅此处了解详情.

@as batoutofhell mention, don't forget to put FacebookSdk.sdkInitialize(getApplicationContext()); to initialize the facebook sdk. Please see here for the details.

这篇关于适用于 Android 的 Facebook SDK 4 - 如何以编程方式注销的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆