I tried the fallowing code to get access twitter timeline. It doesn't received any data from the server.What went wrong here?
ACAccount *twitterAccount=[arrayOfAccounts lastObject];
NSURL *requestURL=[NSURL URLWithString:@"http://api.twitter.com/1/statuses/user_timeline.json"];
NSMutableDictionary *parameters=[NSMutableDictionary new];
//[parameters setObject:@"100" forKey:@"count"];
//[parameters setObject:@"1" forKey:@"include_entities"];
SLRequest *post=[SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodGET URL:requestURL parameters:parameters];
post.account=twitterAccount;
[post performRequestWithHandler:^(NSData *response, NSHTTPURLResponse *urlResponse, NSError *error) {
self.array=[NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableLeaves error:&error];
if(self.array.count !=0)
NSLog(@"%@",self.array);
else
NSLog(@"No Data Recived");
Thanks in advance.
Those
NSError
objects the API gives you? Their purpose is to tell you what went wrong. Use them.Your problem is that you don't know what happened because you just try to convert to JSON. That is what could have went wrong:
To write defensive code (and that's what you want if you want to release this thing to the public) you have to check each of these steps to figure out what went wrong, so you can act accordingly. Yes, that will take more code, but less code is not always the best choice.
Code with better error handling would more look like this. Note how it checks the result of each step that could go wrong:
Twitter has advice to use Version 1.1 not advice v1. In version 1.1 api https,So try to use this url https://api.twitter.com/1.1/statuses/user_timeline.json instated of this url http://api.twitter.com/1/statuses/user_timeline.json. This work's fine.