java代码使用标记名称从Tumblr获取所有帖子

问题描述 投票:2回答:3

我尝试使用标签从Tumblr获取帖子。

http://api.tumblr.com/v2/tagged?tag=hadoop&api_key=*****

我可以编写HTTP客户端,并可以获取json并进行相应的解析。但是我想知道任何支持的tumblr java api之类的信息来访问此信息。

我尝试使用com.tumblr.jumblr.JumblrClient,但没有找到任何支持此要求的方法。有人可以在这方面建议我吗。

java tags fetch tumblr
3个回答
2
投票

如果我查看github中的JumblrClient.java,我可以看到一个方法:

/**
 * Tagged posts
 * @param tag the tag to search
 * @param options the options for the call (or null)
 * @return a list of posts
 */
public List<Post> tagged(String tag, Map<String, ?> options) {
    if (options == null) {
        options = Collections.emptyMap();
    }
    Map<String, Object> soptions = JumblrClient.safeOptionMap(options);
    soptions.put("api_key", apiKey);
    soptions.put("tag", tag);
    return requestBuilder.get("/tagged", soptions).getTaggedPosts();
}

https://github.com/tumblr/jumblr/blob/master/src/main/java/com/tumblr/jumblr/JumblrClient.java

https://github.com/tumblr/jumblr#tagged

根据文档,它应该正是您所需要的。它实际上建立了您在问题中提到的相同请求。

编辑:根据Tumblr API文档,最多要求20个帖子。

限制-要返回的结果数:1-20,含

https://www.tumblr.com/docs/en/api/v2#tagged-method


1
投票

我找到了..

public List<Post> fetchPostsByTag(JumblrClient client, String tagName, long timestamp) {
    if (client == null || tagName == null || tagName.isEmpty()) {
        return null;
    }
    Map<String, String> options = new HashMap<String, String>();
    if (timestamp != 0) {
        options.put("before", timestamp + "");
    }
    List<Post> posts = client.tagged(tagName, options);
    return posts;
}

此代码为我工作..现在我收到超过20个使用标记的帖子。

感谢Re绳的支持。


0
投票

你帮我吗..我在Java中遇到源代码问题。

© www.soinside.com 2019 - 2024. All rights reserved.