2011-06-23 4 views
0

MGTwitterEngine.msoumettre tweet à twitter de l'iphone

- (NSString *)username 
{ 
return [[_username retain] autorelease]; 
} 


- (NSString *)password 
{ 
return [[_password retain] autorelease]; 
} 


- (void)setUsername:(NSString *)newUsername password:(NSString *)newPassword 
{ 


// Set new credentials. 


    [_username release]; 

_username = [newUsername retain]; 

    [_password release]; 


_password = [newPassword retain]; 


if ([self clearsCookies]) { 

    // Remove all cookies for twitter, to ensure next connection uses new credentials. 

    NSString *urlString = [NSString stringWithFormat:@"%@://%@", 
          (_secureConnection) ? @"https" : @"http", 
          _APIDomain]; 

    NSURL *url = [NSURL URLWithString:urlString]; 

    NSHTTPCookieStorage *cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage]; 
    NSEnumerator *enumerator = [[cookieStorage cookiesForURL:url] objectEnumerator]; 
    NSHTTPCookie *cookie = nil; 
    while (cookie == [enumerator nextObject]) { 
     [cookieStorage deleteCookie:cookie]; 
    } 
} 
} 

- (NSString *)sendUpdate:(NSString *)status 
{ 
return [self sendUpdate:status inReplyTo:0]; 
} 


- (NSString *)sendUpdate:(NSString *)status inReplyTo:(unsigned long)updateID 
{ 
if (!status) { 
    return nil; 
} 

NSString *path = [NSString stringWithFormat:@"statuses/update.%@", API_FORMAT]; 


NSString *trimmedText = status; 

if ([trimmedText length] > MAX_MESSAGE_LENGTH) { 


    trimmedText = [trimmedText substringToIndex:MAX_MESSAGE_LENGTH]; 

} 

NSMutableDictionary *params = [NSMutableDictionary dictionaryWithCapacity:0]; 

[params setObject:trimmedText forKey:@"status"]; 

if (updateID > 0) { 

    [params setObject:[NSString stringWithFormat:@"%u", updateID] forKey:@"in_reply_to_status_id"]; 

} 

NSString *body = [self _queryStringWithBase:nil parameters:params prefixed:NO]; 


return [self _sendRequestWithMethod:HTTP_POST_METHOD path:path 
        queryParameters:params body:body 
         requestType:MGTwitterUpdateSendRequest 
         responseType:MGTwitterStatus]; 


} 

TwitterPostViewController.m

- (IBAction)submitTweet{ 

[tweet resignFirstResponder]; 

if([[tweet text] length] > 0){ 


    NSLog(@"%@",[[NSUserDefaults standardUserDefaults] valueForKey:@"TwitterUsername"]); 

    NSLog(@"%@",[[NSUserDefaults standardUserDefaults] valueForKey:@"TwitterPassword"]);  


    [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES]; 

    [engine sendUpdate:[tweet text]]; 

} 

} 



- (void)requestFailed:(NSString *)requestIdentifier withError:(NSError *)error{ 

NSLog(@"Fail: %@", error); 

[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO]; 

UIAlertView *failAlert; 

if([error code] == 401){ 

    failAlert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Incorrect Username & Password." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; 

    [failAlert setTag:10]; 

    [failAlert setDelegate:self]; 

} 
else 
{ 

    failAlert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Failed sending status to Twitter." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; 

} 

[failAlert show]; 

[failAlert release]; 

} 

Il me montre FAIL pop-up de nom d'utilisateur et mot de passe incorrect

J'ai vérifié via nslog ce nom d'utilisateur et mot de passe vont correct. qu'est-ce qui pourrait ne pas fonctionner?

Répondre

0

Il semble que la version de MGTwitterEngine que vous utilisez essaie d'utiliser l'authentification de base. Cela a été désactivé sur Twitter en faveur d'OAuth. Obtenez une version plus récente de MGTwitterEngine (ou une fourchette qui prend en charge OAuth).

+0

comment puis-je faire cela? –