微博开放平台
创建应用获取APPkey和App Secret
APPkey和App Secret
开发文档
开发文档
首先需要重定向到第一个路径:
https://api.weibo.com/oauth2/authorize?
client_id=你的APPKEY
&response_type=code&
redirect_uri=你的回调地址
这里会返回accessToken、uid、expires_in、isRealName、remind_in
官方API
测试人员
代码部分(摘要)
String params = "client_id="+ WeiboConstant.APP_ID
+ "&client_secret=" + WeiboConstant.APP_SECRET
+ "&grant_type=" + "authorization_code"
+ "&redirect_uri=" + WeiboConstant.REDIRECT_URI
+ "&code=" + code;
// 用code换取accessToken
String result = HttpsUtil.post("https://api.weibo.com/oauth2/access_token", params);
@SuppressWarnings("unchecked")
Map map = JSONUtils.toHashMap(result);
String access_token = (String) map.get("access_token");
String uid = (String) map.get("uid");// 这个uid就是微博用户的唯一用户ID
Integer expires_in = (Integer) map.get("expires_in");// 有效期,单位秒
/*Boolean isRealName = map.get("isRealName");
Integer remind_in = map.get("remind_in");*/
// 用uid和accessToken换取用户信息
String resultUser = HttpsUtil.get(
"https://api.weibo.com/2/users/show.json?access_token="+access_token
+"&uid="+uid);
@SuppressWarnings("unchecked")
Map mapUser = JSONUtils.toHashMap(resultUser);
Long id = (Long) mapUser.get("id"); //用户UID
String idstr = (String) mapUser.get("idstr"); //字符串型的用户UID
String screen_name = (String) mapUser.get("screen_name"); //昵称
String profile_image_url = (String) mapUser.get("profile_image_url");//头像
String location = (String) mapUser.get("location"); //地址
String city = (String) mapUser.get("city");//"city":"3",
String description = (String) mapUser.get("description");//简介