Get Published or Received date via Google Feed API v0 or v1

466 views Asked by At

Ahhh, my first post...

I'm using the Google Feed API-v1 (https://developers.google.com/feed/v1/) and have a few RSS feeds where the "publishedDate" is blank i.e - ":", meaning the RSS publisher is not passing an article date into their RSS feed. For instance, I'm pulling articles from http://www.globest.com/index.xml and their feed doesn't have "publishedDate" or "pubDate"; however, when I put www.globest.com/index.xml into Google Reader an article date appears next to the title. I understand that the date appearing next to the article within Google Reader is a "Received" or "Published" date. Google explains the terminology here http://support.google.com/reader/bin/answer.py?hl=en&answer=78728

So my question.... Is there a method in Google Feed API v1 to get "Received" or "Published" date(s)? If yes, how. If no, about v0?

I'm using Java and JSON my code is below:

    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.net.URL;
    import java.net.URLConnection;
    import net.sf.json.JSONObject;

    public class FeedTester 
    {

        public static void main(String[] args) throws IOException 
        {
            String loadBaseURL = "https://ajax.googleapis.com/ajax/services/feed/load";
            String googleRSSURL = "?v=1.0&q=";
            String testRSSURL = "http://www.globest.com/index.xml";
            String extra = "&callback=CB1&num=10";

            URL url = new URL(loadBaseURL+googleRSSURL+testRSSURL+extra);
            URLConnection connection = url.openConnection();
            connection.addRequestProperty("Referer", "www.YOURSITE.com");

            String line;
            StringBuilder builder = new StringBuilder();
            BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
            while((line = reader.readLine()) != null)
            {
                    builder.append(line);
            }

            JSONObject json = new JSONObject();
            json.put("values", builder.toString());

            System.out.println(json.get("values"));
        }//end main
    }//end FeedTester
1

There are 1 answers

1
Hellonearthis On

I'm not sure about Java but in Python you can access the publishedDate below. results is the json response from google.

for entries in results['responseData']['feed']['entries']:  
    print entries['publishedDate']

Hope that helps.