开发者

Parsing Google Reader Data

Hey guys, So I am very new to the Objective-C realm and even newer to the stadium of programming internet connections. I am trying to work on a RSS reader app and have been able to set up a decent NSXMLParser and such to parse the XML feeds. I then wanted to add the ability to tie into Google Reader. I can connect, authenticate and then request from the page but what it returns on my connection is the straight up html code for the site and not the XML of the feed like I was hoping for... My question is How do I get the XML data from the feed from the google reader? Here is my code:

NSMutableURLRequest* request=[NSMutableURLRequest requestWithURL:URL];

[request setValue:[authCodes objectForKey:@"Auth"] forHTTPHeaderField:@"Auth"];
[request setValue:[authCodes objectForKey:@"SID"] forHTTPHeaderField:@"SID"];
//[request setHTTPMethod:@"GET"];

NSURLConnection* conn=[NSURLConnection connectionWithReques开发者_Python百科t:request delegate:self];

[conn start];  

And then the two delegate methods:

-(void)connection: (NSURLConnection *)connection didReceiveData:(NSData *)data
{
if (connectionData==nil) {
        connectionData=[[NSMutableData alloc] init ];
    }
    NSLog(@"CONNECTION");
    [connectionData appendData:data];

}

-(void) connectionDidFinishLoading:(NSURLConnection *)connection
{
    NSLog(@"Connection Closed");

    NSString *tempString = [[NSString alloc] initWithData:connectionData encoding:NSASCIIStringEncoding];
    NSLog(@"The Data is Equal To: %@", tempString);

    rssParser=[[NSXMLParser alloc] initWithData:connectionData];

    [rssParser setDelegate:self];
    [rssParser setShouldProcessNamespaces:YES];
    [rssParser setShouldReportNamespacePrefixes:YES];
    [rssParser setShouldResolveExternalEntities:NO];

    [rssParser parse];

}

It then goes on and parses and obviously is giving me an error saying it doesn't know how to parse it. (error code 76)

This is the URL I'm trying to connect to: http://www.google.com/reader/view/feed/http%3A%2F%2Fnews.cnet.com%2F2547-1_3-0-20.xml

and here is what it is printing out as the data recieved... just kidding when i put it in there Stack Overflow parsed it as HTML and displayed it as such...

I know it isn't an authentication error and really am stumped as to where to go to get the feeds from. Am I getting from the wrong URL? If I know it isn't the parser as it parses just fine cnet's original feed, as well as any other straight from their site.


NSURLConnection will make a request to the URL provided and download whatever data is stored there. When you enter http://www.google.com/reader/view/feed/http://news.cnet.com/2547-1_3-0-20.xml into your web browser, you'll see it takes you to the Google Reader website (HTML), not to an XML feed you can directly parse.

I'm not sure where you're generating your URLs from. If you know the URL to the XML feed itself, you should just use that directly. It looks like the Google Reader URLs are of the form http://www.google.com/reader/view/feed/[feed_url]. So if you have a Google Reader URL already, you can extract the feed URL and use it for your request instead.

If for some reason you absolutely need to go through Google, you can download the HTML and parse it to find _INPUT_STREAM_ID. This contains the URL from which to download the XML, and you can then make a second request.


For those searching to implement this and are still looking here is what I have found to fix this question.

First you must connect to google, then get a token and then interact with the website google.com/reader/api/0/...

here is the site that I found extremely helpful:

http://code.google.com/p/pyrfeed/wiki/GoogleReaderAPI

It outlines the keywords and how to interact with googlereader

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜