简体   繁体   中英

Using the twitter framework for iOS to make a search

I can't understand how can I use the twitter framework included in iOS to make a search... Can someone post an example? Thanks

You can easily use TWRequest class to create a request with correct URL.

See detailed documentation of class on: https://developer.apple.com/library/ios/documentation/Twitter/Reference/TWRequestClassRef/Reference/Reference.html#//apple_ref/doc/uid/TP40010942

To learn how to create Twitter requests, I would advise you to read the following tutorial: http://iosdevelopertips.com/core-services/ios-5-twitter-framework-part-2.html

This code is from the tutorial above and the author makes a search as an example:

#import <Twitter/Twitter.h>

...

// Do a simple search, using the Twitter API
TWRequest *request = [[TWRequest alloc] initWithURL:[NSURL URLWithString:
   @"http://search.twitter.com/search.json?q=iOS%205&rpp=5&with_twitter_user_id=true&result_type=recent"] 
   parameters:nil requestMethod:TWRequestMethodGET];

// Notice this is a block, it is the handler to process the response
[request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error)
{
  if ([urlResponse statusCode] == 200) 
  {
    // The response from Twitter is in JSON format
    // Move the response into a dictionary and print
    NSError *error;        
    NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:responseData options:0 error:&error];
    NSLog(@"Twitter response: %@", dict);                           
  }
  else
    NSLog(@"Twitter error, HTTP response: %i", [urlResponse statusCode]);
}];

For detailed API information, you can check Twitter API documentation .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM