Third party landed Sina Weibo Java version oauth2

Source: Internet
Author: User

The project in the use of Sina Weibo landing needs, online search for a long time, there is no suitable answer. After half a day's effort, finally finished. For the convenience of peers, special will be detailed steps written out, rough writing, laughed.

First of all, to register Sina Weibo account, after the successful registration, in Http://open.weibo.com/development/mobile Open this link,

Create an application, and after the application is created, edit the application's information in my application

These two sets of data are then used in the generated Appkey and App_secret.

Then in the application information, the basic information and advanced information should be filled in. The authorization callback page for advanced information also needs to be filled in Baidu can also be.

Next you need to add a test account to the application,

In the application information to find the test account and then click Edit, add test account, input is the nickname of the account, you can fill in the account name just registered. After you bind the test account, you will download the Java SDK

The address is Http://open.weibo.com/wiki/SDK after you select the Java SDK download to import Eclipse and then find config.properties fill in Appkey and App_secret

As follows:

client_id = Your Appkey

Client_sercret = Your App_secret

Redirect_uri =http://www.baidu.com
BaseURL = https://api.weibo.com/2/
Accesstokenurl = Https://api.weibo.com/2/oauth2/access_token
Authorizeurl = Https://api.weibo.com/2/oauth2/authorize

Then find the Oauth4code class, which will then eject the authorization page (in the state of your Sina Weibo login) to confirm the authorization.   Call the written authorization callback page (Redirect_uri), get the code value, enter the value of the code in Eclipse, and after the console prints the access token and the corresponding UID to token, in the Showuser class The code is as follows:

public class Showuser {public

	static void Main (string[] args) {
		String Access_token = "token you have taken";
		Weibo Weibo = new Weibo ();
		Weibo.settoken (Access_token);
		String uid =  "UID fetched";
		Users um = new users ();
		try {
			User user = Um.showuserbyid (UID);
			Log.loginfo (User.tostring ());
			
		} catch (Weiboexception e) {
			e.printstacktrace ();}}}


After running, you can output the user's information.

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.