Can't post to Twitter from my iPhone app
I'm using this small chunk of code to post in Twitter, with real credentials in place of 'mytwitterlogin开发者_运维问答name' and 'mytwitterpassword' placeholders:
void _StartTwitter()
{
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:
[NSURL URLWithString:@"http://mytwitterloginname:mytwitterpassword@twitter.com/statuses/update.xml"]
cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:30.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(@"Posted to Twitter successfully.");
else
NSLog(@"Error posting to Twitter.");
}
But even my console says the post was succeful it still doesn't happen.
Can anyone help me to find what's wrong ?, thanks.
I though twitter had only O-AUTH authentication now, so you couldn't post information simply through their REST service anymore.
You may need to re-integrate with their new OAUTH service.
UPDATE:
Here is the link to the OAUTH Examples: Twitter - OAUTH
The bummer part that I needed to do was create a WebUI view in order to go through the silly steps twitter now enforces. After doing a request to authenticate (which is bound to an app created in twitter), my session was created and from there I could do my posting of a message.
Not nearly as user friendly as the previous REST service :/
精彩评论