这是本文档旧的修订版!
get请求(页面跳转)
注意:
https://api.weibo.com/oauth2/authorize?client_id=1570065866&response_type=code&redirect_uri=https%3A%2F%2Fapi.weibo.com%2Foauth2%2Fdefault.html
请求成功,会跳转到redirect\_uri同时带上code
https://api.weibo.com/oauth2/default.html?code=d47ad7eeaf07901b9372645b3777a05c
根据code做post请求(可以从服务端请求)
注意:
String url = "https://api.weibo.com/oauth2/access_token"; Map<String, String> mapData = new HashMap<String, String>(); mapData.put("client_id", "1570065866"); mapData.put("client_secret", "388725da138272e2d577fbcf480816ea"); mapData.put("grant_type", "authorization_code"); mapData.put("redirect_uri", "https://api.weibo.com/oauth2/default.html"); mapData.put("code", "d47ad7eeaf07901b9372645b3777a05c"); String content = HttpClientUtils.getWebContentByPost(url, mapData, "GBK"); System.out.println("content=" + content);
返回json,服务端解析得到access\_token和uid
{"access_token":"2.00eaYP_GArpPiB597d053aa6S3d7FD","remind_in":"157679999","expires_in":157679999,"uid":"5781255264"}