Twitter API Rate Limit - Overcoming on an unauthenticated JSON Get with Objective C?

Posted by Cian on Stack Overflow See other posts from Stack Overflow or by Cian
Published on 2011-01-10T20:53:26Z Indexed on 2011/01/11 15:53 UTC
Read the original article Hit count: 277

Filed under:
|
|
|
|

I see the rate limit is 150/hr per IP. This'd be fine, but my application is on a mobile phone network (with shared IP addresses).

I'd like to query twitter trends, e.g. GET /trends/1/json. This doesn't require authorization, however what if the user first authorized with my application using OAuth, then hit the JSON API?

The request is built as follows:

- (void) queryTrends:(NSString *) WOEID {

 NSString *urlString = [NSString stringWithFormat:@"http://api.twitter.com/1/trends/%@.json", WOEID];
 NSURL *url = [NSURL URLWithString:urlString];
 NSURLRequest *theRequest=[NSURLRequest requestWithURL:url
             cachePolicy:NSURLRequestUseProtocolCachePolicy
            timeoutInterval:10.0];


 NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self startImmediately:YES];
 if (theConnection) {
  // Create the NSMutableData to hold the received data.
  theData = [[NSMutableData data] retain];
 } else {
  NSLog(@"Connection failed in Query Trends");
 }

 //NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:urlString]];


}

I have no idea how I'd build this request as an authenticated one however, and haven't seen any examples to this effect online.

I've read through the twitter OAuth documentation, but I'm still puzzled as to how it should work. I've experimented with OAuth using Ben Gottlieb's prebuild library, and calling this in my first viewDidLoad:

 OAuthViewController *oAuthVC = [[OAuthViewController alloc]
       initWithNibName:@"OAuthTwitterDemoViewController" bundle:[NSBundle mainBundle]];
 // [self setViewController:aViewController];
 [[self navigationController] pushViewController:oAuthVC animated:YES];

This should store all the keys required in the app's preferences, I just need to know how to build the GET request after authorizing!

Maybe this just isn't possible? Maybe I'll have to proxy the requests through a server side application?

Any insight would be appreciated!

© Stack Overflow or respective owner

Related posts about iphone

Related posts about objective-c