Giter VIP home page Giter VIP logo

weibo4j-oauth2-beta3.1.1's Introduction

使用方法

1、 请先填写相关配置:在Config.properties里 client_ID :appkey 创建应用获取到的appkey client_SERCRET :app_secret 创建应用获取到的appsecret redirect_URI : 回调地址 OAuth2的回调地址

2、 然后调用example里:OAuth4Code.java

public class OAuth4Code {

public static void main(String [] args) throws WeiboException, IOException{
	Oauth oauth = new Oauth();
	BareBonesBrowserLaunch.openURL(oauth.authorize("code"));
	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();
		}
	}
}

}

3、 运行后会弹出浏览器地址跳转到授权认证页面,然后输入你的微博帐号和密码,会调转到你的回调地址页面,url后面会传递code参数

4、 然后在console输入code就能获取到oauth2的accesstoken

5、 接下来即可调用example,在此以user/show接口为例:

public class ShowUser {

public static void main(String[] args) {
	String access_token = WeiboConfig.getValue("access_token");
	String uid = args[0];
	Users um = new Users(access_token);
	try {
		User user = um.showUserById(uid);
		Log.logInfo(user.toString());
	} catch (WeiboException e) {
		e.printStackTrace();
	}
}

}

access_token为auth4code获取到的oauth2的accesstoken。 由于目前只开放支持code的oauth认证方式,所以sdk暂时只支持code获取token方式。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.