如何从Twitter Rest API v1.1中的FHSTwitterEngine完全注销?

时间:2013-07-06 05:29:12

标签: iphone ios objective-c twitter

FHSTwitterEngine *engine = [FHSTwitterEngine sharedEngine];
[engine clearAccessToken];

我尝试了上面的代码,但是当我再次尝试登录时,presentModalViewController中没有显示文本字段,它显示了授权应用按钮。

另一种方法[engine clearConsumer];会在Select and Copy the PIN中产生presentModalViewController

2 个答案:

答案 0 :(得分:12)

我认为Cookie仍然存在,这是iOS上大多数Twitter API的主要问题。

这是您检查所有Cookie的方法,在两者之间进行检查以清除您在Twitter上执行注销操作的Twitter Cookie:

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

希望它有所帮助。

此致

Reno Jones

答案 1 :(得分:4)

FHSTwitterEngine.hm文件中添加以下方法。

- (void)logout
{
  NSLog(@"Logged out from twitter");

  //These is FHSTwitterEngine class method which clears accesstoken
  [self clearAccessToken]; 

  //clear cache of twitter from NSHTTPCookieStorage
  NSHTTPCookie *cookie;
  NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
  for (cookie in [storage cookies])
  {
    NSString* domainName = [cookie domain];
    NSRange domainRange = [domainName rangeOfString:@"twitter"];
    if(domainRange.length > 0)
    {
        [storage deleteCookie:cookie];
    }
  }
}

编辑:使用以下这些方法:

[[FHSTwitterEngine sharedEngine] logout];