Android新浪微博获取评论信息、发表评论、转发微博等
首先前面一节中说过,获取用户的微博信息,这里简单介绍下获取微博的评论信息,以及对微博进行评论,转发微博等.
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.
下面是实现部分代码:
- /***
- * 获取用户的评论
- *
- * @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;
- }
/***
* 获取用户的评论
*
* @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新浪微博获取评论信息、发表评论、转发微博等的更多相关文章
- 【Android Studio安装部署系列】十一、Android studio获取数字签名信息
版权声明:本文为HaiyuKing原创文章,转载请注明出处! 概述 下面介绍下调试版本和发布版本获取数字签名的方法,通过以下方法可以获取到SHA1和MD5. 一般在使用分享功能,在第三方平台中创建应用 ...
- Android 开发 获取设备信息与App信息
设备信息 设备ID(DeviceId) 获取办法 android.telephony.TelephonyManager tm = (android.telephony.TelephonyManager ...
- 如何通过android代码获取LTE信息?
最近为了成功得到LTE的信号强度,尝试了很多种方法: (1)通过解析signalstrength字符串,但是不同手机设备获得的字符串排列顺序不同,代码如下: private PhoneStateLis ...
- Android之使用MediaMetadataRetriever类获取媒体信息
一.昨天.介绍了使用MediaMetadataRetriever类来获取视频第一帧:http://blog.csdn.net/u012561176/article/details/47858099,今 ...
- Android 获取内存信息
由于工作需要,研究了一下android上获取内存信息的方法,总结如下: 1.SDK获取 在Java层利用API获取很简单,直接使用ActivityManager.MemoryInfo类即可,代码如下: ...
- android之读取联系人信息
联系人信息被存放在一个contacts2.db的数据库中 主要的两张表 读取联系人 读取联系人需要知道联系人内容提供者的地址,以及对应的操作对象.一般情况下操作对象是的命名方式和表明是一致的. 布局文 ...
- [Python爬虫] Selenium爬取新浪微博客户端用户信息、热点话题及评论 (上)
转载自:http://blog.csdn.net/eastmount/article/details/51231852 一. 文章介绍 源码下载地址:http://download.csdn.net/ ...
- 好客租房43-react组件基础综合案例-4获取评论信息
获取评论信息 1使用受控组件方式创建表单 //导入react import React from 'react' import ReactDOM from 'react-dom' //导入组件 // ...
- [Python爬虫] Selenium+Phantomjs动态获取CSDN下载资源信息和评论
前面几篇文章介绍了Selenium.PhantomJS的基础知识及安装过程,这篇文章是一篇应用.通过Selenium调用Phantomjs获取CSDN下载资源的信息,最重要的是动态获取资源的评论,它是 ...
随机推荐
- MySQL文件目录格式及存放位置
了解MYSQL的都知道,在MYSQL中建立任何一张数据表,在其数据目录对应的数据库目录下都有对应表的.frm文件,.frm文件是用来保存每个数据表的元数据(meta)信息,包括表结构的定义等,.frm ...
- XML Schema的基本语法(转)
XML Schema的基本语法(转) XSDL(XML Schema定义语言)由元素.属性.命名空间和XML文档种的其他节点构成的. 一.XSD中的元素 XSD文档至少要包含:schema根元素和XM ...
- leetcde37. Sudoku Solver
Write a program to solve a Sudoku puzzle by filling the empty cells. Empty cells are indicated by th ...
- 无需输入密码的scp/ssh/rsync操作方法
一般使用scp/ssh/rsync传输文件时,都需要输入密码.下面是免密码传输文件的方法. 假设要在两台主机之间传送文件,host_src & host_dst.host_src是文件源地址所 ...
- 【转载】 postman使用教程
一 接口请求流程 二 postman使用 从流程图中我们可以看出,一个接口请求需要设置:请求URL,请求方法,请求头,请求参数.同样的,在postman中,我们也只需要设置这四项即可完成一 ...
- poj3461 字符串匹配 熟悉kmp算法第一题
题意: 计算一个字符串在另一个字符串中出现的次数. #include<cstdio> #include<cstring> #include<algorithm> ...
- DedeCMS织梦动态分页类,datalist标签使用实例
<?php require_once(dirname(__FILE__)."/include/common.inc.php");//载入基础文件 require_once(D ...
- nginx location各种修饰符的匹配优先级
这作为一个备份,方便查询,毕竟nginx的强大,必然有其复杂性! Location modifier Nginx allows you to define location blocks by spe ...
- 获取本机MAC地址
<%@ page contentType="text/html; charset=GBK" %><html><head><meta htt ...
- SQL:查找被锁的表,以及锁表的SQL语句(重点推荐)
--死锁检测 use master Select * --找到SPID exec sp_lock --根据SPID找到OBJID ) --根据OBJID找到表名 1.DatabaseName 同于你要 ...