Sina Weibo API (Java edition)

Source: Internet
Author: User
Tags oauth


Sina Weibo API (Java edition)
============================
Modification matters:
1, the interface returns the result uses the JSON object way to encapsulate
2, modify the Weiboresponse Hollow string ("") call to judge the bug
3. Modified the problem of returning empty object in Jsonobject
4, the increase of direct file upload interface directly

Common Interface Examples:
(Modify the Weibo.java before use)
public static final String Consumer_key = "";
public static final String Consumer_secret = "";
Fill in the actual application of Consumer_key and Consumer_secret)

1. Get the latest public microblog list
Reference: the Getpublictimeline () section in Weibo4j.examples.GetTimelines

2, published micro-blog
Reference: Weibo4j.examples.Update in the UpdateStatus (...) Part

3. Post a comment
Reference: Weibo4j.examples.Update in the Updatecomment (...) Part

4. Delete comments
Reference: Weibo4j.examples.Update in the Destroycomment (...) Part

5. Send Private message
Reference: Weibo4j.examples.DirectMessage class

6, published with pictures of micro-blog
Reference: Uploadstatus (status,file) section of Weibo4j.examples.OAuthUploadByFile

7, update the user avatar
Reference: Weibo4j.examples.OAuthUpdateProfile class

8, OAuth desktop application access
Step: 1> access to the authenticated URL in weibo4j.examples.OAuthUpdate to get the pin
2> enter the pin in the weibo4j.examples.OAuthUpdate and get Accesstoken
3> can access the user's microblog, reference: Weibo4j.examples.OAuthUpdateTwo

9. OAuth Web application Access
Steps:
1> in Weibo4j.examples.WebOAuth with backurl parameter request OAuth authentication, obtain Requesttoken
2> in the callback address, accept the oauth_verifier parameters, and then send a request, you can get Accesstoken
3> use Accesstoken to access users ' tweets
Example Description:

There are two JSP pages under the Web directory:
call.jsp
is the request to be sent and the argument "http://localhost:8080/callback.jsp" in line Nineth is the callback address
When successful, Requesttoken is placed into session and redirected to the user authentication address
callback.jsp
Received the Oauth_verifier parameters, from the session to get Requesttoken, and then request to obtain Accesstoken
When you get there, you can operate on the user's microblog, in this case, the microblog

Test environment:

In this example, call.jsp and callback.jsp can be placed directly under the root directory of Tomcat: Webapps/root
and copy the classes file and Lib directory of the instance project to the Root/web-inf below.
Restart Tomcat, Access http://localhost:8080/call.jsp?opt=1
Note: You can also play the war package, but note that the callback parameters inside the call.jsp need to be modified accordingly.


=============================================================================
Other interfaces are weibo4j. Weibo class, refer to the Weibo4j.examples, and here is the complete list of interfaces:

Gets the downlink data set (Timeline) interface method Name:
Statuses/public_timeline latest Public Microblogging method name: Getpublictimeline
Statuses/friends_timeline latest People's attention Weibo (alias: Statuses/home_timeline) method Name: Getfriendstimeline
Statuses/user_timeline User publishes Weibo list method name: Getusertimeline (String ID, paging paging)
Statuses/mentions the latest @ user's method name: Getmentions ()
Statuses/comments single Comment list (by microblog) method name: Getcomments ()

Micro-Blog Access interface
Statuses/show get a single method name: Showstatus (Long ID)

Statuses/update Publish Weibo method name: UpdateStatus (String status)
Statuses/upload published microblogging and image method name: Uploadstatus (String status,file File)
Statuses/destroy Delete method Name: Destroystatus (Long Statusid)

Statuses/comment Comment Method Name: destroycomment (Long Commentid)
Statuses/comment_destroy Delete Comment Method Name: destroycomment

DMS interface
Direct_messages My DMs list method name: Getdirectmessages () pagination getdirectmessages (paging paging)
Direct_messages/sent I sent the DMs list method name: Getsentdirectmessages ()
Direct_messages/new Send DMS Method name: Senddirectmessage (String id,string text)
Direct_messages/destroy Delete a DMS method name: destroydirectmessage (int id)
Attention Interface
Friendships/create focus on a user method name: createfriendship (string id) or createfriendship (string ID, Boolean follow)
Friendships/destroy Method Name: destroyfriendship (String ID)
Friendships/exists whether to pay attention to a user method name: existsfriendship (String UserA, String UserB)

Friends/ids Attention List Method Name: Getfriendsids (Long cursor)
Followers/ids Fan List method name: Getfollowersids (Long cursor)
Account interface
Account/verify_credentials Verify identity is legal method name: Verifycredentials ()
Account/rate_limit_status View current frequency limiting method name: Ratelimitstatus ()

Account/update_profile_image Change Avatar Method Name: Updateprofileimage (File image)
Account/update_profile change Data method name: User updateprofile (string name, string email, string url, string location, String descript Ion

Favorites Interface
Favorites Favorites List Method name: Getfavorites ()
Favorites/create Add Favorites Method Name: Createfavorite (Long ID)
Favorites/destroy Delete Favorite method name: Destroyfavorite (Long ID)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.