How can i logout from twitter from my application using fabric framework in iOS

后端 未结 4 1369
离开以前
离开以前 2021-01-21 19:50

In my iOS application, i am integrate twitter login using fabric frameworkTWTRComposer”. it is working fine when first time login and post t

相关标签:
4条回答
  • 2021-01-21 20:07

    The [Twitter sharedInstance] object have two method to logout : logOut and logOutGuest.

    Here is the link to the docs: Twitter object iOS reference

    Just FYI you can check if the user is logged in using the session parameter like below

    [[Twitter sharedInstance] session]

    If session is nil then they are not logged in.

    Try below thing if above thing not work, It might be possible cookies still exist.

    NSHTTPCookieStorage *cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
        for (NSHTTPCookie *each in cookieStorage.cookies) {
           // put a check here to clear cookie url which starts with twitter and then delete it
             [cookieStorage deleteCookie:each];
        }
    
    0 讨论(0)
  • 2021-01-21 20:13
    [[Twitter sharedInstance] logOut]
    

    and

    [[Twitter sharedInstance] logOutGuest]
    

    will not work, since as per the docs:

    Deletes the local Twitter user session from this app. This will not remove the system Twitter account nor make a network request to invalidate the session.

    So additionally, you need to invalidate the token returned by oauth. You can get help from twitter's docs. Use this REST webservice in order to invalidate token. Pass access_token to the post request.

    As per the link,

    Allows a registered application to revoke an issued OAuth 2 Bearer Token by presenting its client credentials. Once a Bearer Token has been invalidated, new creation attempts will yield a different Bearer Token and usage of the invalidated token will no longer be allowed.

    Hopefully it helps!

    0 讨论(0)
  • 2021-01-21 20:14

    use this code:

      [[Twitter sharedInstance] logOut];
    
    0 讨论(0)
  • 2021-01-21 20:18

    Removing cookies - doesnt help.

    I invent my own flow for relogin:

    (I need user email to further login so only WebBasedLogin)

    // Get first twitter acc (check if it exists etc...)
    .....
    
    // This method will be used if user the same
    TWTRLoginMethod loginMethod = TWTRLoginMethodSystemAccounts;
    
    // Check if it is the Previous twitter user (whom was stored in userDefaults)
    if (![[STLUserDataManager lastTwitterUser] isEqualToString:[firstTwitterAccount username]])
    {
    // if user is new - ForceLogin
        loginMethod = TWTRLoginMethodWebBasedForceLogin;
    }
    
    // inside completion
    {
     ...
    // Store userName in userDefaults
    [STLUserDataManager storeTwitterUser:[firstTwitterAccount username]];
    }
    
    0 讨论(0)
提交回复
热议问题