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

标签 java json rss rss-reader google-feed-api

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

我正在使用 Google Feed API-v1 (https://developers.google.com/feed/v1/),并且有一些 RSS feed,其中“publishedDate”为空,即“:”,表示RSS 发布者未将文章日期传递到其 RSS 提要中。例如,我正在从 http://www.globest.com/index.xml 中提取文章并且他们的提要没有“publishedDate”或“pubDate”;然而,当我将 www.globest.com/index.xml 放入 Google Reader 时,标题旁边会出现文章日期。据我所知,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 中,您可以访问下面的publishedDate。 results 是来自 google 的 json 响应。

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

希望有帮助。

关于java - 通过 Google Feed API v0 或 v1 获取发布或接收日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10866933/

相关文章:

java - 如何在 JLayer 覆盖的 JComponent 上激活工具提示?

java - 我的应用程序忽略按钮背景颜色的任何更改

php - $_POST 不使用标签形式从输入文本接收数据

python - 修改json文件

java - d 上的 UnknownHostException

java - GroupLayout 的列未对齐

java - 序列化整数[]

java - java中将json字符串反序列化为string对象

c# - 在 .NET 中反序列化 RSS 提要

java - 如何避免 Rome 异常(exception)