How can I log out of twitter from my application using the iOS framework

In my iOS application, I integrate twitter login using the frame structure ofTWTRComposer . It works fine the first time I log in to the system and in the twit message on Twitter. But I couldn’t log out of twitter in my application. And the second time I try log in. twitterlogin view controller cannot open.so pls anyone can give me a solution for successfully logging in and logging out of my application using TWTRComposer

+2
ios twitter
source share
4 answers

The [Twitter sharedInstance] object has two ways to log out: logOut and logOutGuest.

Here is the link to the docs: link to the iOS link of the Twitter

Just FYI you can check if the user is registered using the session parameter as shown below

[[Twitter sharedInstance] session]

If the session is nil, then they are not logged in.

Try below, if nothing works above, maybe 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]; } 
+2
source share
 [[Twitter sharedInstance] logOut] 

and

 [[Twitter sharedInstance] logOutGuest] 

will not work, because according to the documents:

Removes a local Twitter user session from this application. This will not delete the Twitter account or make a network request to cancel the session.

Therefore, you need to invalidate the token returned by oauth. You can get help on twitter. Use this REST web service for invalid token. Pass access_token to the message.

Link,

Allows a registered application to revoke an issued OAuth 2 Token media by presenting the credentials of its client. Once the carrier token has been declared invalid, new attempts to create will give another carrier Token and the use of an invalid token will no longer be allowed.

Hope this helps!

+1
source share

use this code:

  [[Twitter sharedInstance] logOut]; 
0
source share

Removing cookies does not help.

I invent my own thread for relogin:

(I need a user email for 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
source share

All Articles