简体   繁体   中英

logout from Twitter in iPhone using OAuth+MGTwitterEngine Library

I had made the twitter application using the OAuth and MGTwitterEngine Library. The login phase is working fine but I am facing problem in logout. I had referred all the post of logout for OAuth but it doesn't works. So can anyone suggest the perfect method for logout from the Twitter ...? OR What changes I have to make in the Library file for the logout..!!

Did anyone ever find the solution for this? If so, please post!

UPDATE: I figured it out. In the MGTwitterEngine.m, search for _clearCookies in initWithDelegate method. This is currently set to NO, change it to YES. In your action method for logging out the current user, call [_engine clearAccessToken]. Now run it, and voila, it works!

There is no sign out from Twitter OAuth/xAuth... you need to implement client side solution:

  1. persistently store the access token in the keychain or coredata (it never expires unless the user revoke your application from his/her account) when log in and use it in subsequent calls to twitter and " keeping the user signed in"
  2. when signing out delete any related data stored (in this case the access token)

hope that will help

I use this tutorial for integreate twitter to iOS app link

For logout I use next:

[_engine clearAccessToken];

_engine - this is instance of SA_OAuthTwitterEngine class.

You can call this method on your IBAction method.

Also need this method

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults removeObjectForKey:@"authData"];
    [defaults synchronize];

I dont know how to logout. But if you want the login screen every time, do one thing (i dont know this is the right way), delete the login specific data which the engine saves in Userdefaults.

我没有在这里明确说明,但是我在SA_OAuthTwitterEngine中使用了“clearAccessToken”函数来“注销”当前用户。

Might be kinds of stupid, but this seems to work

- (IBAction)logout:(id)sender {
    [_engine dealloc];
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults removeObjectForKey:@"authData"];
    [defaults synchronize];

    [self presentLoginView];
    }

您必须在iPhone应用程序中删除您的帐户,该应用程序位于iPhone的“设置”菜单中。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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