简体   繁体   English

我如何获得,用户登录或登录facebook sdk 4.0.1

[英]How i get, is user login or logout in facebook sdk 4.0.1

I am using Facebook new sdk 4.0.1, in that when i get log-in button changes to log-out and same button is used to logout without any code. 我正在使用Facebook新的sdk 4.0.1,因为当我登录按钮更改为注销时,相同的按钮用于注销而无需任何代码。 but actually i want to do some coding at time of log-out. 但实际上我想在注销时做一些编码。 so how i get differentiate between these two things in that sdk? 那么我如何在sdk中区分这两件事呢? How i declare logout method ? 我如何声明注销方法?

You could check when the token changes, and if the new access token is null, the user just logged out. 您可以检查令牌何时更改,如果新访问令牌为空,则用户刚刚注销。

new AccessTokenTracker() {
    @Override
    protected void onCurrentAccessTokenChanged(AccessToken oldAccessToken, AccessToken newAccessToken) {
        if (newAccessToken==null)
            //your code here!
    }
};

Login Updates 登录更新

Session Removed - AccessToken, LoginManager and CallbackManager classes supercede and replace functionality in the Session class. 会话已删除 - AccessToken,LoginManager和CallbackManager类取代并替换Session类中的功能。

Access Tokens - You can load AccessToken.getCurrentAccessToken with the SDK from cache or if the app is cold launched from an app bookmark. 访问令牌 - 您可以从缓存中加载带有SDK的AccessToken.getCurrentAccessToken,或者如果应用程序是从应用程序书签冷启动的。 For instructions, see Facebook Login for Android, Get Current Token. 有关说明,请参阅Facebook登录Android,获取当前令牌。

Login Button - The easiest way to add Login is to use the LoginButton in 4.x. 登录按钮 - 添加登录的最简单方法是使用4.x中的LoginButton。 See Facebook Login for Android, Add Facebook Login. 查看Facebook登录Android,添加Facebook登录。

UserSettingsFragment class has been removed from the SDK. UserSettingsFragment类已从SDK中删除。

LoginManager is a singleton instance, and works with the AccessToken's currentAccessToken. LoginManager是一个单例实例,可以使用AccessToken的currentAccessToken。 After login the SDK sets currentAccessToken. 登录后,SDK设置currentAccessToken。 To get additional permissions call the logInWith... methods. 要获得其他权限,请调用logInWith ...方法。

LogInWith... methods always open a prompt UI if necessary. 如有必要,LogInWith ...方法始终打开提示UI。 There's no equivalent to the Session.openActiveSessionFromCache or Session.OpenActiveSession(Activity, boolean, StatusCallback). 没有与Session.openActiveSessionFromCache或Session.OpenActiveSession(Activity,boolean,StatusCallback)等效的东西。 Instead, you should check AccessToken.getCurrentAccessToken() at onCreate(), and if not null, skip login. 相反,您应该在onCreate()上检查AccessToken.getCurrentAccessToken(),如果不为null,则跳过登录。

AccessToken broadcast events when it is set, unset or updated. 设置,取消设置或更新时的AccessToken广播事件。 Use the AccessTokenTracker to receive these events. 使用AccessTokenTracker接收这些事件。 See Facebook Login for Android, Track Access Tokens. 请参阅Facebook登录Android,跟踪访问令牌。

currentAccessToken automatically caches when the SDK sets it. 当SDK设置时,currentAccessToken会自动缓存。

ProfileTracker.getCurrentProfile returns the current logged in user. ProfileTracker.getCurrentProfile返回当前登录的用户。

ProfileTracker returns events if the logged in user changes. 如果登录用户更改,ProfileTracker将返回事件。 see Facebook Login for Android, Track Current Profile. 查看Facebook登录Android,跟踪当前个人资料。

CallbackManager.onActivityResult replaces Session.onActivityResult and UiLifecycleHelper.onActivityResult. CallbackManager.onActivityResult替换了Session.onActivityResult和UiLifecycleHelper.onActivityResult。 See Facebook Login for Android, Register a Callback. 查看Facebook登录Android,注册回拨。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM