Sina Weibo Java development-save Accesstoken data as the next login voucher

Source: Internet
Author: User
According to the Sina Open forum some Netizen's introduction, first login needs to enter PIN code, generate Accesstoken data, save, can stay for two times login use, I provide examples of Java SDK to modify and test through.

Write a class Saveaccesstoken.java that provides save and read Accesstoken data.

Modifying Oauthupdate.java as a test

Get authorization code for the first time:

Access to Sina interface:

To save Accesstoken data to a file:

Two login:

Class Saveaccesstoken.java Introduction: Saving and reading Accesstoken data

Save Accesstoken Data

public static void Save (Accesstoken _accesstoken) throws ioexception{
try {
Properties = new properties ();
Property.setproperty ("Accesstoken", _accesstoken.gettoken ());
Property.setproperty ("Accesstokensecret", _accesstoken.gettokensecret ());
Property.store (New FileOutputStream ("Mysave.properties"), "mysave.properties");

System.out.println ("Successfully Save Access Token");
catch (Exception e) {
E.printstacktrace ();
}
}

Reading Accesstoken Data

public static Accesstoken Read (String _filename) throws ioexception{
try {
Properties = new properties ();
Accesstoken accesstoken = null;
Property.load (New FileInputStream (_filename));
Accesstoken _accesstoken=new Accesstoken (Property.getproperty ("Accesstoken"), Property.getproperty (" Accesstokensecret "));

System.out.println ("Successfully Read Access Token");
return _accesstoken;

catch (Exception e) {
E.printstacktrace ();
return null;
}
}

Oauthupdate.java as a test class, modify the Sina Weibo Java SDK with test class

http://download.csdn.net/source/3481549

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.