返回信息流妈蛋弄了好久好不容易爬到微博和评论了,可是!!!为毛只能输出前五十条评论信息?是api本身的限制么?
大哥大姐们知道怎么获取某条微博下的全部评论信息么。。。拙计啊。。。 T T。。。
百度过了,也查过官方问答平台了。。我没找到办法。。。
这是一条镜像帖。来源:北邮人论坛 / ml-dm / #12210同步于 2013/12/17
该镜像源已超过 30 天没有更新,可能在源站已被删除。
ML_DM机器人发帖
【微博api的问题】GetCommentsById输出的评论数量被api限制了?
hainanlxs
2013/12/17镜像同步6 回复
订阅后,新回复会通过你的通知中心匿名送达。
6 条回复
是http://open.weibo.com/wiki/2/comments/show 这个?
count false int 单页返回的记录条数,默认为50。
page false int 返回结果的页码,默认为1。
可以选择页码吧应该
谢谢~不过我不知道这个接口怎么用。之前我是直接用的微博官方java包,就是这个http://code.google.com/p/weibo4j/ 用里面写好的程序抓的数据。你说的这个我只会在API调用示例里用,就是这个http://open.weibo.com/tools/console?uri=comments/show&httpmethod=GET&key1=id&value1=3481474642286341
于是,我的问题就是,如何能在java程序里像API示例那样传入参数调用呢。是post方式?今天有试过。。。
代码片段是:
List<NameValuePair> formparams = new ArrayList<NameValuePair>();
formparams.add(new BasicNameValuePair("access_token", "2.009ys4HCPNnoYCxxxxxx"));
formparams.add(new BasicNameValuePair("id", "3655542544835093"));
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formparams, Consts.UTF_8);
HttpPost httpPost = new HttpPost("https://api.weibo.com/2/comments/show.json");
httpPost.setEntity(entity);
CloseableHttpClient httpclient = HttpClients.createDefault();
CloseableHttpResponse response;
try {
response = httpclient.execute(httpPost);
System.out.println(EntityUtils.toString(response.getEntity()));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
不行。。报如下错:
{"error":"HTTP METHOD is not suported for this request!","error_code":10021,"request":"/2/comments/show.json"}
请问是什么问题呢??谢谢~~
【 在 arthur503 的大作中提到: 】
: 是http://open.weibo.com/wiki/2/comments/show 这个?
: count false int 单页返回的记录条数,默认为50。
: page false int 返回结果的页码,默认为1。
: ...................
"HTTP METHOD is not suported for this request!" 是说HTTP方法不支持,那个api页面里有写,http调用是GET方法。你可以再试一下。
我之前也是用api调用的,你用的是package weibo4j.examples.comment;下的class GetCommentById吧,其中有代码:
CommentWapper comment = cm.getCommentById(id);
你选中getCommentById(id)方法,按F3键跳转到:package weibo4j的public class Comments extends Weibo类,里面有两个方法:
/**
* 根据微博ID返回某条微博的评论列表
*
* @param id
* 需要查询的微博ID
* @return list of Comment
* @throws WeiboException
* when Weibo service or network is unavailable
* @version weibo4j-V2 1.0.1
* @see <a
* href="http://open.weibo.com/wiki/2/comments/show">comments/show</a>
* @since JDK 1.5
*/
public CommentWapper getCommentById(String id) throws WeiboException {
return Comment.constructWapperComments(client.get(
WeiboConfig.getValue("baseURL") + "comments/show.json",
new PostParameter[] { new PostParameter("id", id) }));
}
/**
* 根据微博ID返回某条微博的评论列表
*
* @param id
* 需要查询的微博ID
* @param count
* 单页返回的记录条数,默认为50。
* @param page
* 返回结果的页码,默认为1。
* @param filter_by_author
* 作者筛选类型,0:全部、1:我关注的人、2:陌生人,默认为0。
* @return list of Comment
* @throws WeiboException
* when Weibo service or network is unavailable
* @version weibo4j-V2 1.0.1
* @see <a
* href="http://open.weibo.com/wiki/2/comments/show">comments/show</a>
* @since JDK 1.5
*/
public CommentWapper getCommentById(String id, Paging page,
Integer filter_by_author) throws WeiboException {
return Comment.constructWapperComments(client.get(
WeiboConfig.getValue("baseURL") + "comments/show.json",
new PostParameter[] {
new PostParameter("id", id),
new PostParameter("filter_by_author", filter_by_author.toString()) }, page));
}
第二个就可以使用page参数了。
【 在 hainanlxs 的大作中提到: 】
: 谢谢~不过我不知道这个接口怎么用。之前我是直接用的微博官方java包,就是这个http://code.google.com/p/weibo4j/ 用里面写好的程序抓的数据。你说的这个我只会在API调用示例里用,就是这个http://open.weibo.com/tools/console?uri=comments/show&httpmethod=GET&key1=id&value1=3481474642286341
: 于是,我的问题就是,如何能在java程序里像API示例那样传入参数调用呢。是post方式?今天有试过。。。
: 代码片段是:
: ...................
特别感谢!!!我原来用的是post,居然是get方法……没仔细看…明天我再试试,有问题请大神不吝赐教啊~
【 在 arthur503 的大作中提到: 】
: "HTTP METHOD is not suported for this request!" 是说HTTP方法不支持,那个api页面里有写,http调用是GET方法。你可以再试一下。
: 我之前也是用api调用的,你用的是package weibo4j.examples.comment;下的class GetCommentById吧,其中有代码:
: CommentWapper comment = cm.getCommentById(id);
: ...................
小菜一只,跟大神差距还老远。不过能解答到肯定会回复的~~
【 在 hainanlxs 的大作中提到: 】
: 特别感谢!!!我原来用的是post,居然是get方法……没仔细看…明天我再试试,有问题请大神不吝赐教啊~
今天试了一下get方法,果然成功了。我之前居然傻傻地用api里的examples = =。。。跟普通的get方式没什么区别,而且response出来的东西是json格式,也好解析~~谢谢大神!!!
【 在 arthur503 的大作中提到: 】
: 小菜一只,跟大神差距还老远。不过能解答到肯定会回复的~~