Am learning about iOS programming from book Head First iPhone Programming. In one exercise, they have sample code for Twitter which uses basic authorization. Now that Twitter uses OAuth, how can I get OAuth code so that I can test my client? Do I need to r开发者_StackOverflow中文版egister my app with Twitter? How do I do that, since it's only a test app?
Here is the basic authorization version of the code; I'm looking for the OAuth version:
//TWITTER BLACK MAGIC
NSMutableURLRequest *theRequest=[NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://YOUR_TWITTER_USERNAME:YOUR_TWITTER_PASSWORD@twitter.com/statuses/update.xml"]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:60.0];
[theRequest setHTTPMethod:@"POST"];
[theRequest setHTTPBody:[[NSString stringWithFormat:@"status=%@", themessage] dataUsingEncoding:NSASCIIStringEncoding]];
NSURLResponse* response;
NSError* error;
NSData* result = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:&response error:&error];
NSLog(@"%@", [[[NSString alloc] initWithData:result encoding:NSASCIIStringEncoding] autorelease]);
//END TWITTER BLACK MAGIC
To get Twitter oAuth access you will need to create app on http://dev.twitter.com and retrieve Consumer Key and Consumer Auth.
Perhaps this tutorial will help you:
http://mobile.tutsplus.com/tutorials/iphone/twitter-api-iphone/
精彩评论