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

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

问题描述

最近,Facebook发布了SDK 4,新的和酷的更新。我试图切换到SDK4以使用新功能,但是我正在努力与Facebook的登录功能。



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

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

但SDK4似乎不支持会话,在官方文档中,他们提到:


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



LoginButton类 - 其中提供了一个按钮,您可以添加到您的UI。它遵循当前的访问令牌,并可以记录人员的进出。


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

解决方案

您可以使用 LoginManager。 getInstance()。logOut(); ,即使您使用LoginButton,因为


此UI元素包含功能可用在$ login $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ Facebook SDK v4 。我不知道他们将来会改变它。



@as batoutofhell提到,别忘了把 FacebookSdk.sdkInitialize(getApplicationContext()); 来初始化Facebook sdk。详情请参阅此处


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.

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

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

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

There are two ways to implement Facebook login on Android:

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.

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

解决方案

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

This UI element wraps functionality available in the LoginManager.

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

@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天全站免登陆