【问题标题】:What is a GDATA extension profile?什么是 GDATA 扩展配置文件?
【发布时间】:2010-12-20 09:14:02
【问题描述】:

我想使用 SpreadsheetEntry 继承的 BaseEntry 类的 [generateAtom(..,..)][1] 方法获取 GoogleDocs 电子表格的 atom 格式的 XML。但是我不明白方法中的第二个参数,ExtensionProfile。如果我只想获取原子格式的 XML,它是什么?这个方法调用是否足够?

XmlWriter x = new XmlWriter();
spreadSheetEntry.generateAtom(x,new ExtensionProfile());

[1]:http://code.google.com/apis/gdata/javadoc/com/google/gdata/data/BaseEntry.html#generateAtom(com.google.gdata.util.common.xml.XmlWriter, com.google.gdata.data.ExtensionProfile)

【问题讨论】:

    标签: gdata-api gdata google-data-api


    【解决方案1】:

    细化Jon Skeet's answer,你需要实例化这样的服务:

    String developer_key = "mySecretDeveloperKey";
    String client_id = "myApplicationsClientId";
    YouTubeService service = new YouTubeService(client_id, developer_key);
    

    然后您可以使用服务的扩展配置文件写入文件:

    static void write_video_entry(VideoEntry video_entry) {
        try {
            String cache_file_path = Layout.get_cache_file_path(video_entry);
            File cache_file = new File(cache_file_path);
            Writer writer = new FileWriter(cache_file);
            XmlWriter xml_writer = new XmlWriter(writer);
            ExtensionProfile extension_profile = service.getExtensionProfile();
            video_entry.generateAtom(xml_writer, extension_profile);
            xml_writer.close();
            writer.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    

    类似地,您可以使用服务的扩展配置文件读取文件:

    static VideoFeed read_video_feed(File cache_file_file) {
        VideoFeed video_feed = new VideoFeed();
        try {
            InputStream input_stream = new FileInputStream(cache_file_file);
            ExtensionProfile extension_profile = service.getExtensionProfile();
            try {
                video_feed.parseAtom(extension_profile, input_stream);
            } catch (ParseException e) {
                e.printStackTrace();
            }
            input_stream.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return video_feed;
    }
    

    【讨论】:

      【解决方案2】:

      来自JavaDoc for ExtensionProfile:

      配置文件是一组允许的 每种类型的扩展名以及 其他属性。

      通常,如果您有服务,您可以使用Service.getExtensionProfile() 询问其扩展配置文件。

      【讨论】:

        猜你喜欢
        • 2015-03-04
        • 2010-09-08
        • 2020-06-24
        • 2013-08-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-09-17
        • 2011-08-23
        相关资源
        最近更新 更多