新浪微博JAVA開發-儲存AccessToken資料,可以作為下次登入憑證

來源:互聯網
上載者:User
    根據新浪Open論壇上一些網友的介紹,首次登陸需要輸入數字 PIN 碼,產生AccessToken資料,儲存下來,可以留作二次登入使用,俺以JAVA SDK提供例子修改並測試通過。

    寫一個類SaveAccessToken.java,提供儲存和讀取AccessToken資料。

   修改OauthUpdate.java作為測試

   首次擷取授權碼:

 

 

  訪問新浪介面:

 

將AccessToken資料儲存到檔案:

 

 二次登入:

 

 

  

類SaveAccessToken.java介紹:儲存和讀取AccessToken資料

   //儲存AccessToken資料

    public static void Save(AccessToken _accessToken) throws IOException{
  try {
   Properties property = 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();
  }
 }

  //讀取AccessToken資料

 public static AccessToken Read(String _filename) throws IOException{
  try {
   Properties property = 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作為測試類別,修改新浪微博Java SDK附帶測試類別

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

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.