First of all, as mentioned in the previous section, get the user's Weibo information. Here we will briefly introduce how to get the Weibo comments, comment on Weibo, and forward Weibo information.
Oauth authentication. I will not talk about it here,
I'm talking about the following interface:
Get Weibo Comments List interface: http://api.t.sina.com.cn/statuses/comments.json
We need to request Weibo ID as the parameter here. We can obtain this ID by parsing the user's Weibo information according to the previous section.
Comment on Weibo interface: http://api.t.sina.com.cn/statuses/comment.json
We need to request the Weibo ID and comment as parameters.
Weibo forwarding interface: http://api.t.sina.com.cn/statuses/repost.json
Here we only need the Weibo ID.
The following is the implementation code:
/***** Get user comments ** @ Param requsturl * request URL * @ Param blog_id * Weibo ID * @ return JSON (string) * @ throws oauthmessagesignerexception * @ throws handler * @ throws oauthcommunicationexception * @ throws handler * @ throws ioexception * @ throws jsonexception */public static string handler (string requsturl, string blog_id) throws oauthmessagesignerexception, authorization, oauthcommunicationexception, clientprotocolexception, ioexception, jsonexception {string jsonarray = NULL; httpresponse; httpclient client = new response (); httppost = new httppost (requsturl); Response (); 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.exe cute (httppost); If (httpstatus. SC _ OK = httpresponse. getstatusline (). getstatuscode () {jsonarray = entityutils. tostring (httpresponse. getentity ();} log. I (constant. tag, jsonarray); Return jsonarray ;} /***** comment on a microblog ** @ throws ioexception * @ throws clientprotocolexception * @ throws oauthcommunicationexception * @ throws syntax * @ throws oauthmessagesignerexception */public static Boolean commentblogbyid (string blog_id, string comment, string requsturl) throws exceptions, ioexception, oauthmessagesignerexception, exceptions, oauthcommunicationexception {httpresponse; httpclient client = new response (); 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.exe cute (httppost); If (httpstatus. SC _ OK = httpresponse. getstatusline (). getstatuscode () {return true;} return false ;} /***** Weibo forwarding ** @ Param blog_id * Weibo ID * @ Param requsturl * request URL * @ return * @ throws oauthmessagesignerexception * @ throws oauthexpectationfailedexception * @ throws oauthcommunicationexception *@ throws clientprotocolexception * @ throws ioexception */public static Boolean tranmongodblog (string blog_id, string requsturl) throws oauthmessagesignerexception, exceptions, oauthcommunicationexception, exceptions, ioexception {httpresponse; httpclient client = new response (); httppost = new httppost (requsturl); Response (); 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.exe cute (httppost); If (httpstatus. SC _ OK = httpresponse. getstatusline (). getstatuscode () {return true;} return false ;}
In fact, it is mainly oauth authentication. We only need the corresponding token and tokensecret. These interfaces have nothing to do with. I believe you have read the Sina API.
The following figure shows the effect after implementation:
Obtain the user's comment list from Weibo
Information about the comment on the Weibo comment page
Forwarded Weibo.
The application is under development and the interface is ugly. Sorry.
Well, I have introduced so many Weibo applications. If you have insufficient information, you do not have to raise your hand. Please leave a message to point out.