Code cracker Code cracker - 10 months ago 76
JSON Question

Fetching twitter public feeds as JSON

As a part of my project I need to show the list of tweets in iOS app. I tried with the below code but its returning the JSON. The same code is works fine with version 1. Now the twitter api version is 1.1 and one another warning I got that

TWRequest is deprecated
. This deprecation is not the issue of this even I got same thing with
. Here my problem is I need to fetch the JSON of Particular user tweets without authentication or with authentication

TWRequest *postequest=[[TWRequest alloc]initWithURL:[NSURL URLWithString:@""] parameters:nil requestMethod:TWRequestMethodGET];

[postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
NSString *output;
if ([urlResponse statusCode]==200) {
NSError *err;
NSDictionary *PublicTimeline=[NSJSONSerialization JSONObjectWithData:responseData options:0 error:&err];
output=[NSString stringWithFormat:@"HTTP response status: %li\nPublic timeline:\n%@",(long)[urlResponse statusCode],PublicTimeline];
output=[NSString stringWithFormat:@"No feed HTTP response was: %li\n",(long)[urlResponse statusCode]];

[self performSelectorOnMainThread:@selector(displayResults:) withObject:output waitUntilDone:NO];

-(void)displayResults:(NSString *)text
NSLog(@"tweets feed %@",text);


I used this in my work and it worked pretty well. Use STTwitter. Download STTwitter files here.

Place this in your view didload:

  STTwitterAPI *twitter = [STTwitterAPI twitterAPIAppOnlyWithConsumerKey:@"your consumer key"
                                                        consumerSecret:@"your secret key"];

[twitter verifyCredentialsWithSuccessBlock:^(NSString *bearerToken) {

    [twitter getUserTimelineWithScreenName:@"your twitter account name"
                              successBlock:^(NSArray *statuses) {

                                  self.twitterFeedList = [NSMutableArray arrayWithArray:statuses];

                                  [self->listView reloadData];

                              } errorBlock:^(NSError *error) {

                                  NSLog(@"%@", error.debugDescription);


} errorBlock:^(NSError *error) {

    NSLog(@"%@", error.debugDescription);