05-31-2011, 03:54 PM
#1 (permalink )
Registered Member
Join Date: Apr 2009
Posts: 118
Specific twitter feed in app
Hi,
Been looking around for tutorials on this, but can only find one's related to logging in and posting.
Here all I want to do is show a specific (hardcoded) user's feed, which is presented nicely. I don't need any other functionality.
Anyone know a thread/tutorial that can put me in the right direction?
This is as simple as one of those widgets you see on the side of people's blogs which show their recent tweets
Thanks in advance,
Alex
05-31-2011, 04:58 PM
#2 (permalink )
Senior Member
iPhone Dev SDK Supporter
Join Date: Aug 2008
Location: Memphis, TN, USA
Age: 24
Posts: 3,983
Doubt apple will approve this. But you would just need to the the url for the twitter feed ( see twitter API ), then you can use NSURLConnection to download and NSXMLParser to parse the feed and show it in a table or what ever.
05-31-2011, 05:03 PM
#3 (permalink )
Registered Member
Join Date: Apr 2009
Posts: 118
Thanks,
By user's twitter feed I mean company (the app's for the company) - This is a very small part of the app...
Would they still not approve that?
Alex
06-01-2011, 02:05 AM
#4 (permalink )
Nuisance Developer
Join Date: Jul 2009
Location: Italy
Posts: 4,691
yes, will be approved, if it is just a part of the app....
Code:
http://api.twitter.com/1/statuses/user_timeline.json?screen_name=yourTwitterUser
you can change json in xml if you prefer to have output in xml.
you can see more option here
GET statuses/user_timeline | dev.twitter.com
you need to use ASIHTTPRequest or NSURLConnection to download the timeline from that link and then parse with NSXMLParser or JSON Framework.
__________________
06-01-2011, 04:34 AM
#5 (permalink )
Registered Member
Join Date: Apr 2009
Posts: 118
Cheers that's really helpful... do you know of a tutorial/sample code on how to parse that data? - I have no idea, never used data from the internet in an app before!
06-01-2011, 04:35 AM
#6 (permalink )
Registered Member
Join Date: Apr 2009
Posts: 118
Also what is json? - All I know is that it's used in web APIs!
Thanks,
Alex
06-01-2011, 04:38 AM
#7 (permalink )
Registered Member
Join Date: Apr 2009
Posts: 118
Could this write code that could parse it for you... ?
Objectify on the Mac App Store
Last edited by lexy0202; 06-01-2011 at 06:33 AM .
06-01-2011, 06:45 AM
#8 (permalink )
Nuisance Developer
Join Date: Jul 2009
Location: Italy
Posts: 4,691
Quote:
Originally Posted by
lexy0202
Cheers that's really helpful... do you know of a tutorial/sample code on how to parse that data? - I have no idea, never used data from the internet in an app before!
This tutorial contain the code to do a http request, and also to parse data with NSXMLParser for xml or with JSON Framework for json:
WebService [How-To]
Quote:
Originally Posted by
lexy0202
Also what is json? - All I know is that it's used in web APIs!
Thanks,
Alex
JSON as you can see in the tutorial above is just a textual standard to present data (the same concept of xml)
Quote:
Originally Posted by
lexy0202
No, this should just create Class from JSON....However is a good tool....but read the tutorial, you don't need more than that.
__________________
06-12-2011, 12:12 PM
#9 (permalink )
Registered Member
Join Date: Apr 2009
Posts: 118
Thanks for your help!
Have been using JSON for a while now without a problem.
Up till now.
My app loads the twitter feed fine the first time it loads, but recently I've added a reload button, and as soon as I hit reload, it gives me a twitter error (in HTML). All it tells me is 'Something is technically wrong'.
I'm using the ASIHTTPRequest as demonstrated in the flickr async tutorial, plus I have managed to get reloading to work for images before, so I don't know why it won't work with twitter.
What puzzles me is it is a server-side error, is the framework making a bad request or something??
Thanks,
Alex
06-12-2011, 01:56 PM
#10 (permalink )
Nuisance Developer
Join Date: Jul 2009
Location: Italy
Posts: 4,691
i don't think that someone can help you without know exactly what you done....
yes, seem to be a server error, maybe caused by a wrong approach of using ASIHTTPRequest...
__________________
06-12-2011, 02:35 PM
#11 (permalink )
Registered Member
Join Date: Apr 2009
Posts: 118
how would you suggest I download the data instead??
Alex
06-12-2011, 03:54 PM
#12 (permalink )
Registered Member
Join Date: Apr 2009
Posts: 118
would using NSURLConnection be better??
06-12-2011, 05:18 PM
#13 (permalink )
Nuisance Developer
Join Date: Jul 2009
Location: Italy
Posts: 4,691
i suggest you to post the code if you ask help on a forum....maybe also a project that reproduce the problem can help..
__________________
06-13-2011, 02:50 AM
#14 (permalink )
Registered Member
Join Date: Apr 2009
Posts: 118
Code:
- (void)viewDidLoad {
Reachability *reachManager = [Reachability sharedReachability];
MyAppDelegate *appDelegate = [MyAppDelegate sharedAppDelegate];
[reachManager setHostName:@"api.twitter.com"];
NetworkStatus remoteHostStatus = [reachManager remoteHostStatus];
BOOL reachable = YES;
if (remoteHostStatus == NotReachable) {
reachable = NO;
[[NSNotificationCenter defaultCenter] removeObserver:self];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Network Error" message:@"Could not connect to Twitter (Please check your internet)" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}
else if (remoteHostStatus == ReachableViaWiFiNetwork)
{
[appDelegate.downloadQueue setMaxConcurrentOperationCount:4];
}
else if (remoteHostStatus == ReachableViaCarrierDataNetwork)
{
[appDelegate.downloadQueue setMaxConcurrentOperationCount:NSOperationQueueDefaultMaxConcurrentOperationCount];
}
if (reachable) {
[self loadTweets];
}
}
Then load tweets method kicks off the d/l
Code:
- (void)loadTweets {
NSURL *jsonURL = [NSURL URLWithString:@"http://api.twitter.com/1/statuses/user_timeline.json?screen_name=myUser"];
ASIHTTPRequest *request = [[ASIHTTPRequest alloc] initWithURL:jsonURL];
[request setDelegate:self];
[request setDidFinishSelector:@selector(requestDone:)];
[request setDidFailSelector:@selector(requestFailed:)];
NSOperationQueue *queue = [[MyAppDelegate sharedAppDelegate] downloadQueue];
[queue addOperation:request];
[self.view addSubview:loadingView];
[request release];
}
Finally requestDone method:
Code:
NSData *data = [request responseData];
NSLog(@"%@", [request url]);
NSString *jsonString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"%@", jsonString);
if ([jsonString length] != 0) {
NSArray *array = [jsonString JSONValue];
NSMutableArray *tweetArray = [[NSMutableArray alloc] init];
for (int i = 0; i<[array count]; i++) {
NSDictionary *dict = [array objectAtIndex:i];
NSString *text = [dict objectForKey:@"text"];
NSString *date = [dict objectForKey:@"created_at"];
Tweet *tweet = [[[Tweet alloc] init] autorelease];
tweet.text = text;
tweet.date = date;
[tweetArray addObject:tweet];
}
tweets = [[NSArray alloc] initWithArray:tweetArray];
[myTable reloadData];
[jsonString release];
[tweetArray release];
}
else {
NSLog(@"Failed to download statuses, check connection/filters");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Failed to download" message:@"Please check internet connection/filters" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}
[loadingView removeFromSuperview];
Thread Tools
Display Modes
Linear Mode
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
» Advertisements
» Stats
Members: 175,663
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, LezB44