What is wrong to access your Twitter time-list account?

I tried the code to access twitter timeline. He did not receive any data from the server. What is 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.

+3
source share
2 answers

Twitter has recommendations for using version 1.1, not recommendations v1. There is api https in version 1.1, so try using this url https://api.twitter.com/1.1/statuses/user_timeline.json with this URL http://api.twitter.com/1/statuses/user_timeline.json . This work is wonderful.

+4
source

Those objects NSErrorthat the API gives you? Their goal is to tell you what went wrong. Use them.

, , , JSON. :

  • (, )
  • ,
  • JSON
  • JSON ( ).

( , , ), , , , . , , .

. , , :

[post performRequestWithHandler:^(NSData *response, NSHTTPURLResponse *urlResponse, NSError *error) {
    if (response) {
        // TODO: might want to check urlResponse.statusCode to stop early
        NSError *jsonError;  // use new instance here, you don't want to overwrite the error you got from the SLRequest
        NSArray *array =[NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableLeaves error:&jsonError];
        if (array) {
            if ([array isKindOfClass:[NSArray class]]) {
                self.array = array;
                NSLog(@"resulted array: %@",self.array);
            }
            else {
                // This should never happen
                NSLog(@"Not an array! %@ - %@", NSStringFromClass([array class]), array);
            }
        }
        else {
            // TODO: Handle error in release version, don't just dump out this information
            NSLog(@"JSON Error %@", jsonError);
            NSString *dataString = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding];
            NSLog(@"Received data: %@", dataString ? dataString : response);    // print string representation if response is a string, or print the raw data object
        }
    }
    else {
        // TODO: show error information to user if request failed
        NSLog(@"request failed %@", error);
    }
}];
+3

All Articles