如何获取淘宝 AppKey、AppSecret、SessionKey

获取授权码:https://oauth.taobao.com/authorize

参数:

client_id必选值:你的appkey的值

response_type必选值:code

redirect_uri必选值:urn:ietf:wg:oauth:2.0:oob

最终地址:

https://oauth.taobao.com/authorize?client_id=你的appkey&response_type=code&redirect_uri=urn:ietf:wg:oauth:2.0:oob

获取访问令牌:

client_id必选值:appkey的值

client_secret必选值:appsecret

grant_type必选值:authorization_code

code必选值:授权码

redirect_uri必选值:urn:ietf:wg:oauth:2.0:oob

最终地址:

https://oauth.taobao.com/token?client_id=appkey的值&client_secret=appsecret&grant_type=authorization_code&code=授权码&redirect_uri=urn:ietf:wg:oauth:2.0:oob

获取相关信息:refresh_tokenaccess_token

public static String getToken() throws IOException {
		String url = "";
		Map<String, String> param = new HashMap<String, String>();
		param.put("grant_type", "authorization_code");
		param.put("code", "授权码");
		param.put("client_id", "appKey");
		param.put("client_secret", "appSecret");
		param.put("redirect_uri", "redirect_uri");
		param.put("view", "web");
		param.put("state", "state");
		String responseJson = WebUtils.doPost(url, param, 3000, 3000);
		return responseJson;
	}
	
	public static void main(String[] args) {
		try {
			System.out.println(GetToken.getToken());;
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

相关推荐