Cannot post to twitter with an iPhone app with no errors
I am using at my iPhone app with this code but I can not see the post on my twitter. I am not getting an error back.
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:
[NSURL URLWithString:@"http://username:password@twitter.com/statuses/update.xml"]
cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:15.0];
// The text to post
NSString *msg = @"testing";
// Set the HTTP request method
[request setHTTPMethod:@"POST"];
[request setHTTPBody:[[NSString stringWithFormat:@"status=%@", msg]
dataUsingEncoding:NSASCIIStringEncoding]];
NSURLResponse *response;
NSError *error;
if ([NSURLConnection sendSynchronousRequest:request
returningResponse:&response error:&error] != nil)
NSLog(@"Your Poem posted to Twitter successful开发者_如何学编程ly.");
else
NSLog(@"Could not post to Twitter");
Can anyone tell me what is wrong?
Basic authentication was removed in August. You must now use OAuth. See https://dev.twitter.com/ for details.
Edit: There are several libraries to do this. I have been using this iPhone ready implementation of oauthconsumer: http://github.com/jdg/oauthconsumer
Twitter disabled basic auth recently, you must use OAuth instead.
精彩评论