Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 05-31-2011, 03:54 PM   #1 (permalink)
Registered Member
 
Join Date: Apr 2009
Posts: 118
lexy0202 is on a distinguished road
Default 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
lexy0202 is offline   Reply With Quote
Old 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
smithdale87 is on a distinguished road
Send a message via AIM to smithdale87
Default

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.
smithdale87 is offline   Reply With Quote
Old 05-31-2011, 05:03 PM   #3 (permalink)
Registered Member
 
Join Date: Apr 2009
Posts: 118
lexy0202 is on a distinguished road
Default

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
lexy0202 is offline   Reply With Quote
Old 06-01-2011, 02:05 AM   #4 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

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.
__________________
dany_dev is offline   Reply With Quote
Old 06-01-2011, 04:34 AM   #5 (permalink)
Registered Member
 
Join Date: Apr 2009
Posts: 118
lexy0202 is on a distinguished road
Default

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!
lexy0202 is offline   Reply With Quote
Old 06-01-2011, 04:35 AM   #6 (permalink)
Registered Member
 
Join Date: Apr 2009
Posts: 118
lexy0202 is on a distinguished road
Default

Also what is json? - All I know is that it's used in web APIs!

Thanks,
Alex
lexy0202 is offline   Reply With Quote
Old 06-01-2011, 04:38 AM   #7 (permalink)
Registered Member
 
Join Date: Apr 2009
Posts: 118
lexy0202 is on a distinguished road
Default

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.
lexy0202 is offline   Reply With Quote
Old 06-01-2011, 06:45 AM   #8 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

Quote:
Originally Posted by lexy0202 View Post
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 View Post
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 View Post
Could this write code that could parse it for you... ?

Objectify on the Mac App Store
No, this should just create Class from JSON....However is a good tool....but read the tutorial, you don't need more than that.
__________________
dany_dev is offline   Reply With Quote
Old 06-12-2011, 12:12 PM   #9 (permalink)
Registered Member
 
Join Date: Apr 2009
Posts: 118
lexy0202 is on a distinguished road
Default

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
lexy0202 is offline   Reply With Quote
Old 06-12-2011, 01:56 PM   #10 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

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...
__________________
dany_dev is offline   Reply With Quote
Old 06-12-2011, 02:35 PM   #11 (permalink)
Registered Member
 
Join Date: Apr 2009
Posts: 118
lexy0202 is on a distinguished road
Default

how would you suggest I download the data instead??

Alex
lexy0202 is offline   Reply With Quote
Old 06-12-2011, 03:54 PM   #12 (permalink)
Registered Member
 
Join Date: Apr 2009
Posts: 118
lexy0202 is on a distinguished road
Default

would using NSURLConnection be better??
lexy0202 is offline   Reply With Quote
Old 06-12-2011, 05:18 PM   #13 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

i suggest you to post the code if you ask help on a forum....maybe also a project that reproduce the problem can help..
__________________
dany_dev is offline   Reply With Quote
Old 06-13-2011, 02:50 AM   #14 (permalink)
Registered Member
 
Join Date: Apr 2009
Posts: 118
lexy0202 is on a distinguished road
Default

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];
lexy0202 is offline   Reply With Quote
Reply

Bookmarks

Tags
feed, simple, tweets, twitter

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 334
5 members and 329 guests
Dnnake, iOS.Lover, jenniead38, Kirkout, Wikiboo
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,663
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, LezB44
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:16 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0