iphone - Twitter search for hashtag -
i'm trying parse tweets using twitter framework, write following code , it's working fine, it's not synchronous.
now i'm trying tweets #ios.
i have used following code search result ios hashtag:
-(void)fetchresults { // simple search, using twitter api twrequest *request = [[twrequest alloc] initwithurl:[nsurl urlwithstring: @"http://search.twitter.com/search.json?q=ios%20&rpp=20&with_twitter_user_id=true&result_type=recent"] parameters:nil requestmethod:twrequestmethodget]; // notice block, handler process response [request performrequestwithhandler:^(nsdata *responsedata, nshttpurlresponse *urlresponse, nserror *error) { if ([urlresponse statuscode] == 200) { // response twitter in json format // move response dictionary , print nserror *error; dict = [nsjsonserialization jsonobjectwithdata:responsedata options:0 error:&error]; nslog(@"twitter response: %@", [dict description]); [self filtertweets]; } else nslog(@"twitter error, http response: %i", [urlresponse statuscode]); }]; }
as result got this:
twitter response: { "completed_in" = "0.007"; "max_id" = 333837474914766848; "max_id_str" = 333837474914766848; page = 1; query = quranradios; "refresh_url" = "?since_id=333837474914766848&q=quranradios&result_type=recent"; results = ( { "created_at" = "mon, 13 may 2013 06:53:51 +0000"; "from_user" = yousefmutawe; "from_user_id" = 324385406; "from_user_id_str" = 324385406; "from_user_name" = "yousef n mutawe \uf8ff"; geo = "<null>"; id = 333837474914766848; "id_str" = 333837474914766848; "iso_language_code" = pt; metadata = { "result_type" = recent; }; "profile_image_url" = "http://a0.twimg.com/profile_images/1533729607/20090719526_normal.jpg"; "profile_image_url_https" = "https://si0.twimg.com/profile_images/1533729607/20090719526_normal.jpg"; source = "<a href="http://twitter.com/download/iphone">twitter iphone</a>"; text = "testing #quranradios @mkalatrash"; }, { "created_at" = "sun, 12 may 2013 13:09:43 +0000"; "from_user" = yousefmutawe; "from_user_id" = 324385406; "from_user_id_str" = 324385406; "from_user_name" = "yousef n mutawe \uf8ff"; geo = "<null>"; id = 333569679484416000; "id_str" = 333569679484416000; "iso_language_code" = et; metadata = { "result_type" = recent; }; "profile_image_url" = "http://a0.twimg.com/profile_images/1533729607/20090719526_normal.jpg"; "profile_image_url_https" = "https://si0.twimg.com/profile_images/1533729607/20090719526_normal.jpg"; source = "<a href="http://twitter.com/download/iphone">twitter iphone</a>"; text = "#quranradios :)"; } ); "results_per_page" = 20; "since_id" = 0; "since_id_str" = 0;
}
so use following method filter result , (tweet,username,and user image):
-(void)filtertweets { nsarray *results = [dict objectforkey:@"results"]; //loop through results int x =0; (nsdictionary *tweet in results) { // tweet nsstring *twittext = [tweet objectforkey:@"text"]; nsstring *twitpic = [tweet objectforkey:@"profile_image_url"]; nsstring *username = [tweet objectforkey:@"from_user"]; // save tweet twittertext array [tweetsinfo addobject:(twittext)]; [tweetpics addobject:(twitpic)]; [imagesarray addobject:[uiimage imagewithdata:[nsdata datawithcontentsofurl:[nsurl urlwithstring:[tweetpics objectatindex:x]]]]]; [usernametweet addobject:username]; x++; //nslog(@"tweet ooooooo ======> %@",twitpic); countme++; } [tweetstable reloaddata]; }
i'm not sure if i'm doing right thing,so recommend me do? , how can make synchronized?
am new programming ios, please advice. thanks.
see link parse json message retrieve twitter data on ios 5 after looking @ this: get statuses/public_timeline
Comments
Post a Comment