java 使用标签名称从 Tumblr 获取所有帖子的代码
java code to get all posts from Tumblr using the tag name
我尝试使用标签从 Tumblr 获取帖子。
http://api.tumblr.com/v2/tagged?tag=hadoop&api_key=*****
我可以编写 HTTP 客户端并且可以获得 json 并进行相应的解析。但是我想知道任何支持的 tumblr java api 之类的信息来访问它。
我试过 com.tumblr.jumblr.JumblrClient
但我没有找到任何支持此要求的方法。任何人都可以在这方面建议我。
如果我查看 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 个帖子。
limit - The number of results to return: 1–20, inclusive
我找到了..
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 多个帖子。
感谢 Reins 的支持。
我尝试使用标签从 Tumblr 获取帖子。
http://api.tumblr.com/v2/tagged?tag=hadoop&api_key=*****
我可以编写 HTTP 客户端并且可以获得 json 并进行相应的解析。但是我想知道任何支持的 tumblr java api 之类的信息来访问它。
我试过 com.tumblr.jumblr.JumblrClient
但我没有找到任何支持此要求的方法。任何人都可以在这方面建议我。
如果我查看 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 个帖子。
limit - The number of results to return: 1–20, inclusive
我找到了..
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 多个帖子。
感谢 Reins 的支持。