java获取微博登录api_Java微博授权第三方登陆

微博开放平台

创建应用获取APPkey和App Secret

495445a13de2

APPkey和App Secret

开发文档

495445a13de2

开发文档

首先需要重定向到第一个路径:

https://api.weibo.com/oauth2/authorize?

client_id=你的APPKEY

&response_type=code&

redirect_uri=你的回调地址

这里会返回accessToken、uid、expires_in、isRealName、remind_in

495445a13de2

官方API

495445a13de2

测试人员

代码部分(摘要)

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");//简介

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值