首先前面一节中说过,获取用户的微博信息,这里简单介绍下获取微博的评论信息,以及对微博进行评论,转发微博等.

OAuth认证,这里就不多说了,

我说名一下接口:

获取微博的评论列表接口: http://api.t.sina.com.cn/statuses/comments.json

我们这里需要把微博ID做为参数请求,这个ID我们可以根据前面一节解析用户的微博信息得到.

对微博进行评论接口:http://api.t.sina.com.cn/statuses/comment.json

我们需要把微博的id,与我们的评论comment做为参数进行请求.

微博转发接口:http://api.t.sina.com.cn/statuses/repost.json

这里我们只需要微博的id.

下面是实现部分代码:

  1. /***
  2. * 获取用户的评论
  3. *
  4. * @param requstURL
  5. *            请求url
  6. * @param blog_id
  7. *            微博id
  8. * @return JSON(String)
  9. * @throws OAuthMessageSignerException
  10. * @throws OAuthExpectationFailedException
  11. * @throws OAuthCommunicationException
  12. * @throws ClientProtocolException
  13. * @throws IOException
  14. * @throws JSONException
  15. */
  16. public static String getJSONBlogsComments(String requstURL, String blog_id)
  17. throws OAuthMessageSignerException,
  18. OAuthExpectationFailedException, OAuthCommunicationException,
  19. ClientProtocolException, IOException, JSONException {
  20. String jsonArray = null;
  21. HttpResponse httpResponse;
  22. HttpClient client = new DefaultHttpClient();
  23. HttpPost httpPost = new HttpPost(requstURL);
  24. getTokenAndTokenSecret();
  25. CommonsHttpOAuthConsumer authConsumer = new CommonsHttpOAuthConsumer(
  26. Constant.weiBo.consumerKey, Constant.weiBo.consumerSecret);
  27. authConsumer.setTokenWithSecret(token, tokenSecret);
  28. List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
  29. nameValuePairs
  30. .add(new BasicNameValuePair(Constant.weiBoTag.id, blog_id));
  31. httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs, HTTP.UTF_8));
  32. httpPost.getParams().setBooleanParameter(
  33. CoreProtocolPNames.USE_EXPECT_CONTINUE, false);
  34. authConsumer.sign(httpPost);
  35. httpResponse = client.execute(httpPost);
  36. if (HttpStatus.SC_OK == httpResponse.getStatusLine().getStatusCode()) {
  37. jsonArray = EntityUtils.toString(httpResponse.getEntity());
  38. }
  39. Log.i(Constant.TAG, jsonArray);
  40. return jsonArray;
  41. }
  42. /***
  43. * 评论一条微博
  44. *
  45. * @throws IOException
  46. * @throws ClientProtocolException
  47. * @throws OAuthCommunicationException
  48. * @throws OAuthExpectationFailedException
  49. * @throws OAuthMessageSignerException
  50. */
  51. public static boolean CommentBlogByID(String blog_ID, String comment,
  52. String requstURL) throws ClientProtocolException, IOException,
  53. OAuthMessageSignerException, OAuthExpectationFailedException,
  54. OAuthCommunicationException {
  55. HttpResponse httpResponse;
  56. HttpClient client = new DefaultHttpClient();
  57. HttpPost httpPost = new HttpPost(requstURL);
  58. getTokenAndTokenSecret();
  59. CommonsHttpOAuthConsumer authConsumer = new CommonsHttpOAuthConsumer(
  60. Constant.weiBo.consumerKey, Constant.weiBo.consumerSecret);
  61. authConsumer.setTokenWithSecret(token, tokenSecret);
  62. List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
  63. nameValuePairs
  64. .add(new BasicNameValuePair(Constant.weiBoTag.id, blog_ID));
  65. nameValuePairs.add(new BasicNameValuePair(Constant.weiBoTag.comment,
  66. comment));
  67. httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs, HTTP.UTF_8));
  68. httpPost.getParams().setBooleanParameter(
  69. CoreProtocolPNames.USE_EXPECT_CONTINUE, false);
  70. authConsumer.sign(httpPost);
  71. httpResponse = client.execute(httpPost);
  72. if (HttpStatus.SC_OK == httpResponse.getStatusLine().getStatusCode()) {
  73. return true;
  74. }
  75. return false;
  76. }
  77. /****
  78. * 微博转发
  79. *
  80. * @param blog_ID
  81. *            微博id
  82. * @param requstURL
  83. *            请求URL
  84. * @return
  85. * @throws OAuthMessageSignerException
  86. * @throws OAuthExpectationFailedException
  87. * @throws OAuthCommunicationException
  88. * @throws ClientProtocolException
  89. * @throws IOException
  90. */
  91. public static boolean TranspondBlog(String blog_ID, String requstURL)
  92. throws OAuthMessageSignerException,
  93. OAuthExpectationFailedException, OAuthCommunicationException,
  94. ClientProtocolException, IOException {
  95. HttpResponse httpResponse;
  96. HttpClient client = new DefaultHttpClient();
  97. HttpPost httpPost = new HttpPost(requstURL);
  98. getTokenAndTokenSecret();
  99. CommonsHttpOAuthConsumer authConsumer = new CommonsHttpOAuthConsumer(
  100. Constant.weiBo.consumerKey, Constant.weiBo.consumerSecret);
  101. authConsumer.setTokenWithSecret(token, tokenSecret);
  102. List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
  103. nameValuePairs
  104. .add(new BasicNameValuePair(Constant.weiBoTag.id, blog_ID));
  105. httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs, HTTP.UTF_8));
  106. httpPost.getParams().setBooleanParameter(
  107. CoreProtocolPNames.USE_EXPECT_CONTINUE, false);
  108. authConsumer.sign(httpPost);
  109. httpResponse = client.execute(httpPost);
  110. if (HttpStatus.SC_OK == httpResponse.getStatusLine().getStatusCode()) {
  111. return true;
  112. }
  113. return false;
  114. }
/***
* 获取用户的评论
*
* @param requstURL
* 请求url
* @param blog_id
* 微博id
* @return JSON(String)
* @throws OAuthMessageSignerException
* @throws OAuthExpectationFailedException
* @throws OAuthCommunicationException
* @throws ClientProtocolException
* @throws IOException
* @throws JSONException
*/
public static String getJSONBlogsComments(String requstURL, String blog_id)
throws OAuthMessageSignerException,
OAuthExpectationFailedException, OAuthCommunicationException,
ClientProtocolException, IOException, JSONException {
String jsonArray = null;
HttpResponse httpResponse;
HttpClient client = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(requstURL);
getTokenAndTokenSecret();
CommonsHttpOAuthConsumer authConsumer = new CommonsHttpOAuthConsumer(
Constant.weiBo.consumerKey, Constant.weiBo.consumerSecret);
authConsumer.setTokenWithSecret(token, tokenSecret); List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs
.add(new BasicNameValuePair(Constant.weiBoTag.id, blog_id));
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs, HTTP.UTF_8));
httpPost.getParams().setBooleanParameter(
CoreProtocolPNames.USE_EXPECT_CONTINUE, false); authConsumer.sign(httpPost);
httpResponse = client.execute(httpPost); if (HttpStatus.SC_OK == httpResponse.getStatusLine().getStatusCode()) {
jsonArray = EntityUtils.toString(httpResponse.getEntity());
}
Log.i(Constant.TAG, jsonArray);
return jsonArray;
} /***
* 评论一条微博
*
* @throws IOException
* @throws ClientProtocolException
* @throws OAuthCommunicationException
* @throws OAuthExpectationFailedException
* @throws OAuthMessageSignerException
*/
public static boolean CommentBlogByID(String blog_ID, String comment,
String requstURL) throws ClientProtocolException, IOException,
OAuthMessageSignerException, OAuthExpectationFailedException,
OAuthCommunicationException {
HttpResponse httpResponse;
HttpClient client = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(requstURL);
getTokenAndTokenSecret();
CommonsHttpOAuthConsumer authConsumer = new CommonsHttpOAuthConsumer(
Constant.weiBo.consumerKey, Constant.weiBo.consumerSecret);
authConsumer.setTokenWithSecret(token, tokenSecret); List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs
.add(new BasicNameValuePair(Constant.weiBoTag.id, blog_ID));
nameValuePairs.add(new BasicNameValuePair(Constant.weiBoTag.comment,
comment)); httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs, HTTP.UTF_8));
httpPost.getParams().setBooleanParameter(
CoreProtocolPNames.USE_EXPECT_CONTINUE, false);
authConsumer.sign(httpPost); httpResponse = client.execute(httpPost); if (HttpStatus.SC_OK == httpResponse.getStatusLine().getStatusCode()) {
return true;
}
return false;
} /****
* 微博转发
*
* @param blog_ID
* 微博id
* @param requstURL
* 请求URL
* @return
* @throws OAuthMessageSignerException
* @throws OAuthExpectationFailedException
* @throws OAuthCommunicationException
* @throws ClientProtocolException
* @throws IOException
*/
public static boolean TranspondBlog(String blog_ID, String requstURL)
throws OAuthMessageSignerException,
OAuthExpectationFailedException, OAuthCommunicationException,
ClientProtocolException, IOException {
HttpResponse httpResponse;
HttpClient client = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(requstURL);
getTokenAndTokenSecret();
CommonsHttpOAuthConsumer authConsumer = new CommonsHttpOAuthConsumer(
Constant.weiBo.consumerKey, Constant.weiBo.consumerSecret);
authConsumer.setTokenWithSecret(token, tokenSecret); List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs
.add(new BasicNameValuePair(Constant.weiBoTag.id, blog_ID)); httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs, HTTP.UTF_8));
httpPost.getParams().setBooleanParameter(
CoreProtocolPNames.USE_EXPECT_CONTINUE, false);
authConsumer.sign(httpPost); httpResponse = client.execute(httpPost); if (HttpStatus.SC_OK == httpResponse.getStatusLine().getStatusCode()) {
return true;
}
return false;
}

其实主要是Oauth认证,我们只需要相应的Token 和Tokensecret,这些接口没有什么,相信大家看过新浪API都会的.

下面是实现后的效果:

             

获取用微博的评论列表                                            获取用户的评论列表

             

微博评论界面                                                   刚评论的信息

转发的微博.

Android新浪微博获取评论信息、发表评论、转发微博等的更多相关文章

  1. 【Android Studio安装部署系列】十一、Android studio获取数字签名信息

    版权声明:本文为HaiyuKing原创文章,转载请注明出处! 概述 下面介绍下调试版本和发布版本获取数字签名的方法,通过以下方法可以获取到SHA1和MD5. 一般在使用分享功能,在第三方平台中创建应用 ...

  2. Android 开发 获取设备信息与App信息

    设备信息 设备ID(DeviceId) 获取办法 android.telephony.TelephonyManager tm = (android.telephony.TelephonyManager ...

  3. 如何通过android代码获取LTE信息?

    最近为了成功得到LTE的信号强度,尝试了很多种方法: (1)通过解析signalstrength字符串,但是不同手机设备获得的字符串排列顺序不同,代码如下: private PhoneStateLis ...

  4. Android之使用MediaMetadataRetriever类获取媒体信息

    一.昨天.介绍了使用MediaMetadataRetriever类来获取视频第一帧:http://blog.csdn.net/u012561176/article/details/47858099,今 ...

  5. Android 获取内存信息

    由于工作需要,研究了一下android上获取内存信息的方法,总结如下: 1.SDK获取 在Java层利用API获取很简单,直接使用ActivityManager.MemoryInfo类即可,代码如下: ...

  6. android之读取联系人信息

    联系人信息被存放在一个contacts2.db的数据库中 主要的两张表 读取联系人 读取联系人需要知道联系人内容提供者的地址,以及对应的操作对象.一般情况下操作对象是的命名方式和表明是一致的. 布局文 ...

  7. [Python爬虫] Selenium爬取新浪微博客户端用户信息、热点话题及评论 (上)

    转载自:http://blog.csdn.net/eastmount/article/details/51231852 一. 文章介绍 源码下载地址:http://download.csdn.net/ ...

  8. 好客租房43-react组件基础综合案例-4获取评论信息

    获取评论信息 1使用受控组件方式创建表单 //导入react import React from 'react' import ReactDOM from 'react-dom' //导入组件 // ...

  9. [Python爬虫] Selenium+Phantomjs动态获取CSDN下载资源信息和评论

    前面几篇文章介绍了Selenium.PhantomJS的基础知识及安装过程,这篇文章是一篇应用.通过Selenium调用Phantomjs获取CSDN下载资源的信息,最重要的是动态获取资源的评论,它是 ...

随机推荐

  1. web前端基础篇⑧

    1.伪类选择器 都以冒号开始.:focus 焦点的地方加样式:first-child 向元素的第一个子元素添加样式锚伪类:a:link {color:red} 未访问的链接 a:visited {co ...

  2. RSA IOS和Java

    整了三天 终于可以相互加密解密了,今天我给大家讲讲我遇到的大坑. 这篇文章只是做一个整理,帮大家理清一下步骤的而已 在ios端做证书 来实现我们和java的交流 需要4个文件. 一.首先,打开Term ...

  3. Spark随笔(二):深入学习

    一.如何选择粗粒度和细粒度 从底层往上引申来理解粗粒度与细粒度. 一层:一个类,具有三个属性值.为了查询这个类的所有实例,细粒度查询的程度为属性值,即依次查询每个实例化对象的属性值,查询三次:粗粒度按 ...

  4. Hadoop随笔(一):工作流程的源码

    一.几个可能会用到的属性值 1.mapred.map.tasks.speculative.execution和mapred.reduce.tasks.speculative.execution 这两个 ...

  5. cassandra中对节点失败与否的探测方法, the Phi accrual Failure Dector,附论文

    (1)在分布式系统中,对于某个节点是否还“活着”的探测,通常是设定一个时间的阀值,然后根据接收到的“心跳”信息的间隔,来判定这个节点是否还活着,然后返回一个bool值: 但这种做法很容易造成误判:因为 ...

  6. 【LeetCode OJ】Binary Tree Level Order Traversal II

    Problem Link: https://oj.leetcode.com/problems/binary-tree-level-order-traversal-ii/ Use BFS from th ...

  7. svn Q&A

    Q1:在svn commit的时候,会出现某某文件 is missing.这是因为此次提交时:远程repository中并没有该文件,而且本地repository也没有该文件. 具体原因: 1.可能因 ...

  8. mySql-通过group by分组

    当我们想查询主表和子表的信息时,我们首先会通过主表的id和子表中的主表id关联 如现有主表:tbl_enquire_price(询价表)和子表:tbl_enquire_price_detail(询价详 ...

  9. 【学习笔记】Oracle-1.安装及配置

    Win7旗舰版安装Oracle_11gR1_database:  http://my.oschina.net/laiwanshan/blog/89951 Oracle用户登陆 sqlplus sys/ ...

  10. mysql保存数据提示1366 Incorrect string value: ‘\xF0\x9F\x98\x8A\xF0\x9F…’ 解决

    在保存数据时我们如果页面编辑与数据库字段编码不一样或字符集超出你了mysql数据库中的字符类型就有可能出一\\xF0\\x9F\\x98\\x8A\\xF0\\x9F提示了,下面我来简单的解决方法. ...