pdenlinger
pdenlinger

Reputation: 3917

Looking for OAuth version of Twitter code for iOS client

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 register 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:[email protected]/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 

Upvotes: 1

Views: 2519

Answers (1)

kakilangit
kakilangit

Reputation: 1350

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/

Upvotes: 1

Related Questions