【问题标题】:How to logout from twitter using Fabric Sdk for android如何使用适用于 Android 的 Fabric Sdk 从 Twitter 注销
【发布时间】:2015-06-26 22:19:15
【问题描述】:

我用过

Twitter.getSessionManager().clearActiveSession();

这不起作用,下次我使用 twitter 登录时,它会使用浏览器打开对话框,进行先前的登录,然后询问“允许应用程序获取您的数据吗?”,但不询问用户名和密码。任何我们将不胜感激。

【问题讨论】:

  • 尝试删除应用程序缓存目录并使用Browser.clearHistory(getContentResolver());删除浏览器数据,仍然是同样的问题

标签: android logout twitter-fabric


【解决方案1】:

我终于找到了解决这种情况的方法。

无意中在 Twitter SDK Kit for Android 中找到了一个方法

CookieSyncManager.createInstance(this);
CookieManager cookieManager = CookieManager.getInstance();
cookieManager.removeSessionCookie();
Twitter.getSessionManager().clearActiveSession();
Twitter.logOut();

这个很简单,找了半个小时左右。

适用于 3.0 及以上版本

CookieSyncManager.createInstance(this);
CookieManager cookieManager = CookieManager.getInstance();
cookieManager.removeSessionCookie();
TwitterCore.getInstance().getSessionManager().clearActiveSession()

【讨论】:

  • 知道如何为 IOS 目标 c 执行此操作吗?
  • 我在任何地方都找不到任何对此的参考。我想知道该方法是否是异步的,或者它实际上是做什么的。织物记录不充分:(
  • CookieSyncManager 现已弃用。 CookieManager.flush 是一种可能的替代方案。
  • 'android.webkit.CookieSyncManager' 已弃用。 @moyheen 你能展示一下如何使用 CookieManager.flush 的示例 sn-p 吗?
  • @DroidWormNarendra 如果您仍然需要帮助,您可以在下面查看我的答案。
【解决方案2】:

现在 CookieSyncManager 已被弃用,我这样做:

public void logoutTwitter() {
        TwitterSession twitterSession = TwitterCore.getInstance().getSessionManager().getActiveSession();
        if (twitterSession != null) {
            ClearCookies(getApplicationContext());
            Twitter.getSessionManager().clearActiveSession();
            Twitter.logOut();
        }
}

public static void ClearCookies(Context context) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
            CookieManager.getInstance().removeAllCookies(null);
            CookieManager.getInstance().flush();
        } else {
            CookieSyncManager cookieSyncMngr=CookieSyncManager.createInstance(context);
            cookieSyncMngr.startSync();
            CookieManager cookieManager=CookieManager.getInstance();
            cookieManager.removeAllCookie();
            cookieManager.removeSessionCookie();
            cookieSyncMngr.stopSync();
            cookieSyncMngr.sync();
        }
    }

【讨论】:

    【解决方案3】:

    上一个可行的解决方案:

    public static void logoutTwitter() {
        TwitterSession twitterSession = TwitterCore.getInstance().getSessionManager().getActiveSession();
        if (twitterSession != null) {
            clearTwitterCookies(mAppContext);
            Twitter.getSessionManager().clearActiveSession();
            Twitter.logOut();
        }
    }
    
    public static void clearTwitterCookies(Context context) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
            CookieManager.getInstance().removeAllCookies(null);
            CookieManager.getInstance().flush();
    
        } else {
            CookieSyncManager cookieSyncMngr = CookieSyncManager.createInstance(context);
            cookieSyncMngr.startSync();
            CookieManager cookieManager = CookieManager.getInstance();
            cookieManager.removeAllCookie();
            cookieManager.removeSessionCookie();
            cookieSyncMngr.stopSync();
            cookieSyncMngr.sync();
        }
    }
    

    【讨论】:

    • 很抱歉,但这对我不起作用。我总是让最后一个用户登录。我正在使用最新版本。
    【解决方案4】:

    以上方法已绝迹。

    // twitter log out
    TwitterCore.getInstance().getSessionManager().clearActiveSession();
    

    【讨论】:

      【解决方案5】:

      您现在可以使用:

      Digits.logout();
      

      【讨论】:

        【解决方案6】:
        TwitterCore.getInstance().getSessionManager().clearActiveSession();
        

        这个是logout使用Twitter Auth登录时的方法

        【讨论】:

          【解决方案7】:

          退出当前用户只需调用

          mTwitter.shutdown();
          

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2015-05-11
            • 2018-09-17
            • 1970-01-01
            • 2014-12-25
            • 2015-09-28
            • 1970-01-01
            • 2015-11-02
            • 2015-01-26
            相关资源
            最近更新 更多