通过 Google Feed API v0 或 v1 获取发布或接收日期



啊,我的第一篇文章...

我正在使用 Google Feed API-v1 (https://developers.google.com/feed/v1/),并且有一些 RSS 提要,其中"发布日期"为空白,即 - ":",这意味着 RSS 发布者没有将文章日期传递到他们的 RSS 提要中。例如,我正在从 http://www.globest.com/index.xml 中提取文章,而他们的提要没有"发布日期"或"发布日期";但是,当我 www.globest.com/index.xml 放入Google阅读器时,标题旁边会出现文章日期。我了解 Google 阅读器中文章旁边显示的日期是"接收"或"发布"日期。谷歌在这里解释了术语 http://support.google.com/reader/bin/answer.py?hl=en&answer=78728

所以我的问题....Google Feed API v1 中是否有一种方法可以获取"已接收"或"已发布"日期?如果是,如何。如果没有,大约 v0?

我正在使用Java和JSON,我的代码如下:

    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

我不确定Java,但在Python中,您可以访问下面的publishDate。结果是来自谷歌的 JSON 响应。

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

希望有帮助。

最新更新