The first is to obtain OAuth certification, resume a OAuth class inside the operation of the certification, the process I will be in the next blog, then to get the user's attention to the user ID, Weibo and other information needs to be the following JSON address query.
Http://api.t.sina.com.cn/statuses/friends_timeline.json,
An introduction to the API for this operation is available by clicking on the link below to see the official instructions.
Http://open.weibo.com/wiki/index.php/Statuses/friends_timeline
After the user has OAuth authentication, we can start to get the user information and microblogging of the users concerned.
OAuth oauth=new OAuth ();
String url = "Http://api.t.sina.com.cn/statuses/friends_timeline.json";
List params=new ArrayList ();
Params.add (New Basicnamevaluepair ("source", Oauth.consumerkey));
HttpResponse response =oauth. Signrequest (User.gettoken (), User.gettokensecret (), URL, params);
if (200==response.getstatusline (). Getstatuscode ()) {
try{
InputStream is=response.getentity (). getcontent ();//Return the body of the Web page as InputStream
BufferedReader reader=new BufferedReader (New InputStreamReader (IS), 4000)//read 4,000 bytes at a time
StringBuffer sb=new stringbuffer ((int) response.getentity (). Getcontentlength ());
try{
Char[] Tmp=new char[1024];
int l;
while ((L=reader.read (TMP))!=-1) {
If you haven't finished reading it,
Sb.append (tmp,0,l);
}
}finally{
Reader.close ();
}
String str=sb.tostring ();
Response.getentity (). Consumecontent ();
Jsonarray data=new Jsonarray (str);
for (int i=0;i<data.length (); i++)
{
This is the query login users all concerned about the Id,text and other information
Jsonobject D=data.getjsonobject (i);
LOG.E ("JSON", "RS:" + d.getstring ("Created_at"));
if (d!=null) {
Jsonobject u=d.getjsonobject ("user");
if (D.has ("Retweeted_status")) {
Jsonobject r=d.getjsonobject ("Retweeted_status");
}
Weibo ID
Id=d.getstring ("id");
String userid=u.getstring ("id");
String username=u.getstring ("Screen_name");
String usericon=u.getstring ("Profile_image_url");
LOG.E ("Usericon", Usericon);
String time=d.getstring ("Created_at");
String text=d.getstring ("text");
String followers_count=d.getstring ("Followers_count");
String description=d.getstring ("description");
You can also query a lot of information, here is not detailed, here is a return of the JSON you guys, look at that.
Boolean Haveimg=false;
if (D.has ("Thumbnail_pic")) {
Haveimg=true;
String thumbnail_pic=d.getstring ("Thumbnail_pic");
LOG.E ("Thumbnail_pic", thumbnail_pic);
}
Date Date=new date (time);
Time=date.togmtstring ();
if (wblist==null) {
Wblist=new arraylist<weiboinfo> ();
}
Weiboinfo w=new weiboinfo ();
W.setid (ID);
W.SETUSER_ID (USERID);
W.setusername (UserName);
W.setrealeasetime (time);
W.setusercontent (text);
W.setishaveimage (HAVEIMG);
W.setuser_icon (Usericon);
Wblist.add (w);
}
}
}catch (IllegalStateException e) {
E.printstacktrace ();
catch (IOException e) {
E.printstacktrace ();
catch (Jsonexception e) {
E.printstacktrace ();
}
}
Then it gets the information that the login user is concerned about, then the following is to achieve the attention of the function, here can be concerned about the user's username and its ID to pay attention to, the official recommended use ID because of fear to avoid duplication, to use ID attention must obtain the user's authorization, here I two ways to speak:
The first is the username, by the following address to pay attention to NI to pay attention to the user name users, the following username is you want to pay attention to the microblogging user's nickname
Http://api.t.sina.com.cn/friendships/create/:userName.format
This address will return a JSON that is your focus on the user's information
List params=new ArrayList ();
OAuth oauth=new OAuth ();
Params.add (New Basicnamevaluepair ("source", Oauth.consumerkey));
HttpResponse Response=oauth. Signrequest (User.gettoken (), User.gettokensecret (), "http://api.t.sina.com.cn/friendships/create/" +username+. Format ", params);
If you need to do something else, then do a JSON query to get the information in a similar way.
Here is the second type of authorization to obtain the ID of the authorized user to query
This process is also the first to get the user ID, which should be obtained in the OAuth authentication, get this ID to be similar to the above operation just change the JSON address to:
"http://api.t.sina.com.cn/friendships/create/" +userid () + ". JSON"
OK, here's the two-paragraph JSON code returned.
1, inquires the user to visit the login user's information:
[{"Created_at"  : "Tue Nov 16:21:13 +0800", "text" &NBSP;: "Forward micro bo." "," truncated "&NBSP;: false," Retweeted_status "&NBSP;: {" Created_at "&NBSP;:" Tue Nov 16:05:41 +0800 "," Text "&NBSP:" The starting point of the treatment of things, the foothold, determines the development of things and the result of development. This result is actually a relative success or failure. Secular pursuit of such success and failure but also adjust the point of departure, but not to find a foothold. So be good or lose, put down the best.
"," truncated "&NBSP;: false," in_reply_to_status_id "&NBSP;:" "," annotations "&NBSP;
[], "In_reply_to_screen_name" &NBSP;: "", "Geo" &NBSP;: null, "User"  : {"name" &NBSP: "Return to Long imprint", "Domain" &NBSP;: "", "ge
O_enabled "&NBSP;: true," Followers_count "&NBSP;: 66710," Statuses_count "&NBSP;: 77, "Favourites_count"  : 0, "City"  : "1", "description" &NBSP; The birth of the WTO to help people return to Yuan Monastery official website: http://wWw.guiyuanchansi.net "," verified "&NBSP;: true," id "&NBSP;: 1799833402," ge NDEr " :" M "," Friends_count "&NBSP;: 4," Screen_name " :" Yuan Long yin ","
Allow_all_act_msg "&NBSP;: false," following "&NBSP;: false," url " :" HTTP://1 ", "Profile_image_url" &NBSP;: "http://tp3.sinaimg.cn/1799833402/50/1283207796", "Created_at" &NBSP;
"Tue Aug 00:00:00 +0800", "Province" &NBSP;: "A", "Location" &NBSP;: "Wuhan, Hubei" }, "Favorited" &NBSP;: false, "in_reply_to_user_id" &NBSP;: "", "id" &NBSP;: 39803
64843, "source" &NBSP;: "<a href=/" http://t.sina.com.cn/"rel=/" nofollow/"> Sina Weibo </a>"}, "in_reply_to_status_id" &NBSP;: "", "Annotations" &NBSP;: [], "In_reply_to_screen_na Me "&NBSP;:" ","Geo "&NBSP: null," User " : {" name "&NBSP;:" Ban la slippers "," Domain "&NBSP;:" Banlatuo Xie "," geo_enabled "&NBSP;: true," Followers_count "&NBSP;:" Statuses_count "&NBSP; 333, "Favourites_count"  : 1, "City" &NBSP;: "5", "description" &NBSP;: "Here, I'll just send the words Go, there's no one to ignore my business. "," verified "&NBSP;: false," id "&NBSP;: 1799824787," Gender "&NBSP;:" M ","
Friends_count " :" "Screen_name" &NBSP;: "Ban la slippers", "allow_all_act_msg" &NBSP;: false, "Following" &NBSP;: false, "url" : "Http://blog.sina.com.cn/lingdianjingq", "Profile_image_ URL " :" HTTP://TP4.SINAIMG.CN/1799824787/50/1289443070/1 "," Created_at "&NBSP;:" Sun Sep 05 00:00:00 +0800 "," Province " :" One "," Location "&NBSP;:" Chaoyang District, Beijing "}," Favorited "&NBSP;: F
Alse, "in_reply_to_user_id"  : "", "id"  : 3980654229, "source" &NBSP;: "<a href=/" Http://t.sina.
com.cn/"rel=/" nofollow/"> Sina Weibo </a>"}, ...]
2, after the attention returned JSON { "name": "zhangwei217245", "domain": "zhangwei217245", "Geo_ena Bled ": true, " Followers_count ": + " Statuses_count ": 119, " Favourites_count " : 3 "City": "5", "description": "ABCDE", "verified": false, Status ": { " created_at ":" Mon Dec 13:47:10 +0800 ", "text": "A Storage System ~ ~ ~ I think it is the title party", "truncated": false, "Retweeted_status": { "created_at": "Mon De C 11:09:56 +0800 ", " text ":" A storage system, from the high end design very human, too love. (Via:http://sinaurl.cn/hb5abi) ", " bmiddle_pic ":" http://ww2.sinaimg.cn/ Bmiddle/69b7fcafgw6dc2pwus9ekg.gif ",   "original_pic": "Http://ww2.sinaimg.cn/large/69b7fcafgw6dc2pwus9ekg.gif", & nbsp "truncated": false, "in_reply_to_status_id": "", & nbsp "annotations": [ ] "In_reply_to_screen_name": "", , &NB Sp "Geo": null, "user": { ' name ': ' Madbrief ', &NB Sp "Domain": "madbrief", "geo_enabled": true, "Followers_count": 929, Statu SeS_count ": 1581, " Favourites_count ": 0, &NBS P "City": "3", "description": "Crazy Briefing | Madbrief. Com about creative and business ", " verified ": false, , &NBS P "id": 1773665455 "gender": "M", &NB Sp "Friends_count": 565, Screen_name ":" Madbrief ", " allow_all_act_msg ": false, &NB Sp "following": false, "ur L: "http://www.madbrief.com/" "Profile_image_url": "HTTP://TP4 .SINAIMG.CN/1773665455/50/1290503872/1 ", " created_at ":" Mon June 12 00:00:00 +0800 " " province ":" A ", &NB Sp "location": "Zhejiang Wenzhou" }, "favorited": false, "thumbnail_pic": "Http://ww2.sinaimg.cn/thum Bnail/69b7fcafgw6dc2pwus9ekg.gif, "in_reply_to_user_id": "", &NB Sp "id": 4117314145 "source": "<a href=/" http://t.sina.c om.cn/"rel=/" nofollow/"> Sina Weibo </a>" }, "In_reply_to_statu s_id ":" "annotations": [ ], &NBsp "In_reply_to_screen_name": " " GEO ": null, " favorited ": False "in_reply_to_user_id": "", , "id": 4120818179, &NBS P "source": "<a href=/" http://t.sina.com.cn/"rel=/" nofollow/"> Sina micro-blog </a>" }, "id": 1658122963, "gender": "M", "Friends_count": +, "Screen_n Ame ":" zhangwei217245 ", " allow_all_act_msg ": false, " following ": false, " url " : "", "Profile_image_url": "http://tp4.sinaimg.cn/1658122963/50/1282754213", "Created_at": "Tue Nov 00:00:00 +0800 2009", "province": "One", "location": "Chaoyang District, Beijing"}