2010-05-28 85 views
2

我正在開發一個使用Twitvid庫將視頻上傳到TwitVid的iPhone應用程序。 該庫首先使用用戶名和密碼輸入參數對應用程序進行身份驗證。然後它上傳視頻。 但是,最近我切換到OAuth身份驗證機制,導致用戶可以輸入用戶名和密碼的網頁。 因此,我無法在我的應用程序中爲用戶名和密碼提供上傳視頻的輸入字段。使用OAuth將視頻上傳到Twitter

有人可以幫我解決這個問題。

感謝和問候, 迪帕

回答

2

我認爲你已經使用SA_OAuthTwitterEngineDelegate是OAuth。如果在SA_OAuthTwitterController.m文件中用下面的方法替換現有的方法。我認爲這會有所幫助。

- (BOOL) webView: (UIWebView *) webView shouldStartLoadWithRequest: (NSURLRequest *) request navigationType: (UIWebViewNavigationType) navigationType { 
    NSData    *data = [request HTTPBody]; 

    char    *raw = data ? (char *) [data bytes] : ""; 

    if (raw && strstr(raw, "cancel=")) { 
     [self denied]; 
     return NO; 
    } 
    else if ([[[request URL] absoluteString] isEqualToString:@"http://twitter.com/oauth/authorize"]) { 
     NSString *str = [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease]; 
     NSRange range = [str rangeOfString:@"password"]; 
     NSLog(@"%d",range.location); 
     if (range.location != NSNotFound) { 
      NSString *strPass = [str substringFromIndex:range.location+8]; 
      NSRange toRang = [strPass rangeOfString:@"&oauth_token="]; 
      strPass = [strPass substringToIndex:toRang.location]; 
      NSArray *tempArray = [strPass componentsSeparatedByString:@"="]; 
      if ([tempArray count]) { 
       strPass = [tempArray objectAtIndex:1]; 
       NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; 
       [defaults setObject:strPass forKey:@"pass"]; 
      } 
     } 
    } 
    if (navigationType != UIWebViewNavigationTypeOther) 
     _webView.alpha = 0.1; 
    return YES; 
} 

乾杯, Pragnesh