Package weibo4j.examples.oauth2

Source Code of weibo4j.examples.oauth2.OAuth4Code

package weibo4j.examples.oauth2;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import weibo4j.Oauth;
import weibo4j.model.WeiboException;
import weibo4j.util.BareBonesBrowserLaunch;

public class OAuth4Code {
  public static void main(String[] args) throws WeiboException, IOException {
    Oauth oauth = new Oauth();
    BareBonesBrowserLaunch.openURL(oauth.authorize("code", args[0], args[1]));
    System.out.println(oauth.authorize("code", args[0], args[1]));
    System.out.print("Hit enter when it's done.[Enter]:");
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String code = br.readLine();
    Log.logInfo("code: " + code);
    try {
      System.out.println(oauth.getAccessTokenByCode(code));
    } catch (WeiboException e) {
      if (401 == e.getStatusCode()) {
        Log.logInfo("Unable to get the access token.");
      } else {
        e.printStackTrace();
      }
    }
  }

}
TOP

Related Classes of weibo4j.examples.oauth2.OAuth4Code

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.