Getting started with Sina Weibo API: Application, authorization, use of the official Java version SDK

Source: Internet
Author: User
Tags oauth
Rice Seed Original, Welcome to reprint, please specify the source: Http://blog.csdn.net/ffanfanmP.S. The project is developed using the Java language Eclipse platform, and the configuration process is based on this.
develop a general flow chart

Let your app run on Sina Weibo's open platform with just six simple steps:


Become a developer

1. Create Weibo account

On the developer page http://open.weibo.com/development click "Login" or "Create application" to log in as a developer through an account. A Sina Weibo account can manage 10 different applications, and it is recommended that developers use the official Weibo account for unified management.


2. Select Application Type

Click "Create Application" to enter the type selection link for the target application. Select the appropriate application creation process, depending on the hint of the application type. The type I chose when I created the application was "other" because I wanted to develop a Java client software. (inside information can be randomly filled in, application development completed and then back to modify.) After creation, the system assigns an app key and app secret to verify the identity of the developer, write it down, and use it later.


3. Developer Information Settings

Fill in the information on the Developer Information Settings page. To become a Sina Weibo certified developer, you need to verify by email and phone.

Note: Once the developer type is filled in, it cannot be modified. Personal developers are not available to pay the business, please choose carefully.


Application Development

1. Download the SDK source code

Into the Http://open.weibo.com/wiki/SDK#Java_SDK download SDK, download the decompression as a project to import eclipse.

2. Address Authorization Errors

Resolving to obtain user authorization is due to the error:redirect_uri_mismatch caused by the error of the callback address filling.

Sina Weibo open platform → Select the management center → Click on the application name to enter the corresponding application → left application information → advanced information →oauth2.0 authorization settings Click edit → site application Redirect_uri equal to application information in the "Station application address" instead of "apply the actual address" ; Other applications: Redirect_uri needs to be changed into

Http://open.weibo.com/apps/30871*****/info/advanced (30871***** replaces the appkey you apply).

If you are outside the website application or client application, fill in the Redirect_uri address:

http://open.weibo.com/apps/Application Appkey/privilege/oauth

Note: It takes about half an hour or so for a change to apply a callback page or bound domain name to take effect.

3. Fill in the relevant configuration

In Eclipse's project, fill in the relevant configuration: in Config.properties.

Client_id:appkey

Client_sercret:app_secret

Redirect_uri: Callback address (required to be consistent with Redirect_uri in step 3rd)

4. Modify Engineering Code

In Eclipse's project, modify the Weibo4j.examples.oauth2.OAuth4Code.java file, comment 14 lines, and 15 lines, followed by inserting the following code:

Barebonesbrowserlaunch.openurl (Oauth.authorize ("Code", "", ""));

The result of the modification is as shown in the figure:


5. Authorization

Start by running the Weibo4j.examples.oauth2.OAuth4Code.java file you just modified, boot the user to the authorization page, and click "Authorize" if the user agrees to authorize it. System callback application, the page jumps to Your_registered_redirect_uri/?code=code, in exchange for Accesstoken.

Record the Accesstoken following the address bar "code" in the page after the callback application:

Authorization level and oauth2.0access_token validity table:

Authorization level Test General intermediate advanced

Authorized validity 1 days 7 days 30 days 90 days

Note:

Only applications that have not been audited by Copywriting are at the test level.

The application is valid for 5 years when the developer is authorized to apply.

Access_token Automatic Continuation scheme

If the user reopened the authorization page authorization within the validity period of the authorization (if the user has Weibo login status, the page will flash over), then Sina will automatically extend the Access_token life cycle for developers, ask the developer to maintain the new authorization after the Access_token value.

How to query the currently applied authorization level

You can query the currently applied authorization level on the http://open.weibo.com/apps/application Appkey/privilege/oauth.

6. Test

If you want to get a user's information, you can run

Weibo4j.examples.user.ShowUser files, you need to configure two parameters in the Runconfigurations to be viewed by the user ID and just the "Code" code.

The results of the run are displayed on the command line:


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.