Sina Weibo API (Java version)

Source: Internet
Author: User
Tags oauth

Sina Weibo API (Java version)
======================================
Modification items:
1. The interface return result is encapsulated as a JSON object
2. Modify the bug of weboresponse Null String ("") Call judgment
3. modified the problem of returning null objects in jsonobject.
4. added the direct file upload interface

Common interface instances:
(Modify Weibo. java before use
Public static final string consumer_key = "";
Public static final string consumer_secret = "";
Enter the actual applied consumer_key and consumer_secret)

1. Get the latest public Weibo list
See getpublictimeline () in weibo4j. Examples. gettimelines.

2. Posting Weibo
See updatestatus (...) in weibo4j. Examples. Update

3. post comments
See updatecomment (...) in weibo4j. Examples. Update

4. delete comments
See destroycomment (...) in weibo4j. Examples. Update

5. Send private messages
Reference: weibo4j. Examples. directmessage class

6. Posting Weibo Images
See uploadstatus (status, file) in weibo4j. Examples. oauthuploadbyfile.

7. update user portraits
Reference: weibo4j. Examples. oauthupdateprofile class

8. oauth desktop application access
Step: 1> access the authenticated URL in weibo4j. Examples. oauthupdate to obtain the pin
2> enter the pin in weibo4j. Examples. oauthupdate and obtain the accesstoken.
3> you can access your Weibo account. For more information, see weibo4j. Examples. oauthupdatetwo.

9. oauth web application access
Steps:
1> request oauth in weibo4j. Examples. weboauth with the backurl parameter to obtain the requesttoken
2> In the callback address, the oauth_verifier parameter is received and a request is sent again to obtain the accesstoken.
3> Use accesstoken to access your Weibo account
Instance description:

There are two JSP pages under the web directory:
Call. jsp
Is the request sent. The parameter "http: // localhost: 8080/callback. jsp" in the ninth line is the callback address.
After obtaining the token, place the requesttoken in the session and redirect it to the user authentication address.
Callback. jsp
Receives the oauth_verifier parameter, obtains the requesttoken from the session, and then requests the accesstoken.
After obtaining the information, you can perform operations on your Weibo account. In this example, you can post a Weibo account.

Test environment:

In this example, call. jsp and callback. jsp can be directly put under the Tomcat root directory: webapps/root
And copy the compiled classes file and lib directory of the Instance project to the root/WEB-INF.
Restart Tomcat and access http: // localhost: 8080/call. jsp? Opt = 1
Note: You can also compress a war package. Note that the callback parameter in call. jsp must be modified accordingly.

========================================================== ============================================
Other interfaces are defined in the weibo4j. Weibo class. For the call method, see weibo4j. examples. The following is a complete list of interfaces:

Method Name for obtaining the downlink dataset (timeline) interface:
Statuses/public_timeline latest public microblog Method Name: getpublictimeline
Statuses/friends_timeline Weibo (alias: statuses/home_timeline) method name: getfriendstimeline
Statuses/user_timeline: getusertimeline (string ID, paging)
Statuses/mentions latest @ user Method Name: getmentions ()
Statuses/comments single comment list (by Weibo) method name: getcomments ()

Weibo access interface
Statuses/show to obtain the name of a single method: showstatus (long ID)

Statuses/update: updatestatus (string status)
Statuses/upload: uploadstatus (string status, 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

Private message interface
Direct_messages my private message list method name: getdirectmessages () pagination getdirectmessages (paging)
Direct_messages/sent the method name of the private message list I sent: getsentdirectmessages ()
Direct_messages/New Method for sending private messages: senddirectmessage (string ID, string text)
Direct_messages/destroy delete a private message method name: destroydirectmessage (int id)
Follow Interface
Friendships/create follow a user Method Name: createfriendship (string ID) or createfriendship (string ID, Boolean follow)
Method Name: destroyfriendship (string ID)
Whether friendships/exists follows a user Method Name: existsfriendship (string usera, string userb)

Friends/IDS follow list method name: getfriendsids (long cursor)
Followers/IDS: getfollowersids (long cursor)
Account Interface
Account/verify_credentials: verifycredentials ()
Account/rate_limit_status view current frequency limit method name: ratelimitstatus ()

Account/update_profile_image Method for changing the avatar name: updateprofileimage (File image)
Account/update_profile Method for changing data: User updateprofile (string name, string email, string URL, string location, string description)

Add to favorites
Favorites: getfavorites ()
Favorites/create add to favorites Method Name: createfavorite (long ID)
Favorites/destroy: 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.