Help - Search - Members - Calendar
Full Version: Using Google.API to return NEWS?
Movable Type Community Forum > Additional Resources > Tips and Tricks
professor_hojo
hey everyone,

i've successfully got moveabletype to display some returned google search result... but i'm wondering whether it's possible to return news.google.com results instead?

thanks in advance,

professor_hojo
nolageek
QUOTE (professor_hojo @ May 22 2003, 01:28 AM)
hey everyone,

i've successfully got moveabletype to display some returned google search result... but i'm wondering whether it's possible to return news.google.com results instead?

thanks in advance,

professor_hojo

Have you seen gnews2rss? You can either use it from their site, or download it and use it on your own (recommended)

I'm going to use it when I get nolgay.com up and running with movabletype.
jhoke
QUOTE
Have you seen gnews2rss? You can either use it from their site, or download it and use it on your own (recommended)


Wow, this is great! I am using it on my site to post any google news about Gov. Howard Dean's Presidential Bid (1/2 way down on the right)

Using gnews2rss and the mt-rss plugin it works like a charm, I set up a cronjob to update my google feed every 1/2 hr and rebuild the index

Thanks!
biggrin.gif
konakevin@hotmail.com
Wow, jhoke, that news feed on your site is really cool.

Would you mind entering a little tutorial about how to add something like that (a google news feed) to my site? I read the link that nolageek mentioned, but it doesn't explain clearly how to set it up. Sorry, I'm kind of a newbie when it comes to RSS.

I'd really appreciate it if you would!

Thanks,

Kevin
jhoke
QUOTE
Would you mind entering a little tutorial about how to add something like that (a google news feed) to my site


Er..
Ok, first thing I need to say is that I only started using MT this week so if I mis-speak or other wise screw up please bear with me wink.gif

First thing I did was install mt-list and mt-rss_feed both available at
http://www.mplode.com/tima/files/mt-plugins/

Be sure to check out this tutorial on the install of rss_feed it is VERY good & easy to follow to boot smile.gif

Now, go get the sourcecode for gnews2rss (see earlier posts for url) and put it up on your site. I called my grabnews.php

I set up a cronjob on my host as follows:

*/30 * * * * lynx --source "http://my.server.com/grabnews.php?q=Howard+Dean&num=15" > /path/to/mt/dean.xml

That goes and grabs new headlines every 30 minutes (I also use mt-rebuild.cgi in a cronjob that rebuilds the index right after this...)


This creates a RSS file in the same directory as my MT install, so I used the mt-rss_feed locally to pull it in as follows:

Enter the following where you want the feed to appear:

CODE
<!-- Start News Scrapes-->
<div class="sidetitle">
News
</div>
<div class="side">
<MTList name="feeds">
       http://www.yourserver.com/dean.xml
       </MTList>
       <MTListLoop name="feeds">
       <MTRSSFeed>
<u>Google News: Gov. Howard Dean</u><br/>
               <MTRSSFeedItems lastn="7">
               <li><a href="<$MTRSSFeedItemLink$>" target="_blank" ><$MTRSSFeedItemTitle$></a><br />
               </MTRSSFeedItems>
       </MTRSSFeed>
       </MTListLoop>
       <p>Syndicated using <a href="http://www.mplode.com/tima/files/mt-plugins/#mt-rssfeed";>mt-rssfeed</a></p>
</div>
<!-- End News Scrapes-->


Rebuild the index and away ya go ...

I am sure that there is a more elegant and optimized way to do this, but it works and in my book that's 99% of the battle :-D
konakevin@hotmail.com
Okay, I read that tutorial, and have both of the plugins mentioned in it installed. I can successfully get the default feeds from the install of those files.

Now, how do I make the next step and customize the news topic?

The part I'm stuck on, is the gnews2rss .php file. How do I use that code in my site? You said you created a file called grabnews.php. What are you doing with this file, and where do you put it?

Thanks,

Kevin
konakevin@hotmail.com
I am trying to use the gnews2rss php code on my site, but when I run it, I don't get any links, just the root element. Click My Webpage to see what I mean.

After hours of aggrivation, I finally figured out that it was because my hosting service runs PHP in safe mode. This script won't work in safe mode because it won't allow the google news feed to be read.

Arrgghhh!!! Time to find a new host that will allow me to run PHP not in safe mode. Does anyone know of any that will allow this?
almuhajabah
I had the same problem trying to use the code on my own site. Thanks for finding out what the problem is.
ajstano
I would like to put up the identical headlines from the blogforamerica. How did you accomplish this? Can you give a tutorial on this process. Also, how do you check whether your provider is running php in safe mode?

Thanks,
AJ
almuhajabah
The Blog for America might have an RSS feed. You can use the RSS feed plugin to pull in the content. The Google News thing is because Google doesn't generate its own RSS feed.

I'm not sure how konakevin figured out the safe mode thing. All I know is that I copied the PHP script to my server and when I try to run it I don't get any results back.
konakevin@hotmail.com
You will have to inquire of your host as to whether or not they run PHP in safe mode.

I emailed my hosting company, along with a link to the site that works (gnews2rss on the voidstar website), and a link to the .php page that I uploaded to my own site. I told them what the problem was, and that it was an exact copy of the php code on voidstar, so it didn't make sense for mine not to work.

If you look at the php code, it tries to open the two google news url's, and these return the xml items. It was this code that caught my attention, which made me think that it was related to my hosting company running in safe mode:

CODE
 $num = ($num) ? $num+1 : "16";
 $url = "http://news.google.com/news?num=$num&scoring=d&q=".urlencode($q);
 $num2 = $num-1;
 $url2 = "news.google.com/news?num=$num2&scoring=d&q=".urlencode($q);

 if ($fp = @fopen($url, "r")) {
   while (!feof($fp)) $data .= fgets($fp, 128);
   fclose($fp);


Trying to open a remote URL is a potential security hole, and it isn't allowed in safe mode. That's why I asked my host if they ran php in safe mode...and it turned out to be the case.
almuhajabah
That makes sense. My host got much more strict about PHP scripts several months ago and even before that I had a problem with a referrers script that checked URLs to see if they were genuine referrers - it worked OK for every site but Google. So I'm not entirely surprised that the gnews2RSS script doesn't work for me, now that I see what's going on.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.