Monika Patel
Monika Patel

Reputation: 2375

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

In my iOS application, i am integrate twitter login using fabric frameworkTWTRComposer”. it is working fine when first time login and post twit on twitter. but i m not able to done logout from twitter in my application. and second time when i am try to login. twitterlogin view controller not able to open. so pls any one can give me solution for successfully login and logout from my application using TWTRComposer

Upvotes: 2

Views: 3091

Answers (4)

Mike
Mike

Reputation: 61

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]];
}

Upvotes: 0

Nilesh Patel
Nilesh Patel

Reputation: 6394

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];
    }

Upvotes: 2

NightFury
NightFury

Reputation: 13546

[[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!

Upvotes: 1

Dharmesh Dhorajiya
Dharmesh Dhorajiya

Reputation: 3984

use this code:

  [[Twitter sharedInstance] logOut];

Upvotes: 0

Related Questions