【问题标题】:Using the Google API Java Client to parse publicly shared Calendar RSS feeds使用 Google API Java 客户端解析公开共享的日历 RSS 提要
【发布时间】:2012-01-10 18:27:39
【问题描述】:

我正在尝试构建一个 Android 应用程序,该应用程序在来自公共日历 RSS 提要的列表中显示 Google 日历条目。日历提要是公开的,但不与任何特定用户共享。

我已经在 iOS 端使用 Google 的 gdata 库(结合公共日历 RSS)解析和显示公共日历提要。

很遗憾,gdata 与 Android 不兼容。 Google 拥有新的 google-api-java-client 库,但所有示例代码都与设备上的 google 帐户一起使用,然后通过 OAuth 进行身份验证。

有什么方法可以使用这些新库获取和解析公共提要,而无需在设备上存储身份验证信息?甚至根本不进行身份验证?

【问题讨论】:

    标签: android rss google-calendar-api google-api-java-client


    【解决方案1】:

    我找到了解决方案。 Google Api Java 客户端示例中的当前 YouTube 示例就是一个很好的例子。

    http://code.google.com/p/google-api-java-client/wiki/SampleProgram

    谜题中缺少的部分是:

    1. 扩展 GoogleUrl 类(我使用了 CalendarUrl)
    2. 创建匹配 jsonc 输出的对象 feed(您可以通过将 &alt=jsonc 附加到 Feed URL 的末尾)
    3. 注释 (@Key("NameOfField")) 步骤 2 中的对象以匹配 jsonc 名称

    完成此操作后,以下代码将构建并获取您需要的一切:

    HttpTransport transport = new NetHttpTransport();
    final JsonFactory jsonFactory = new JacksonFactory();
    HttpRequestFactory factory = transport.createRequestFactory(new HttpRequestInitializer() {
            @Override
            public void initialize(HttpRequest request) {
                // set the parser
                JsonCParser parser = new JsonCParser(jsonFactory);
                request.addParser(parser);
                // set up the Google headers
                GoogleHeaders headers = new GoogleHeaders();
                headers.setApplicationName("Google-CalendarSample/1.0");
                headers.gdataVersion = "2";
                request.setHeaders(headers);
            }
    });
    
    CalendarUrl url = new CalendarUrl(YOUR_FEED_URL);
    
    HttpRequest request = factory.buildGetRequest(url);
    CalendarFeed feed = request.execute().parseAs(CalendarFeed.class);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多