From 881a87ed95108e588c3b1f4eead36a9752a1bf98 Mon Sep 17 00:00:00 2001 From: "yadong.zhang" Date: Wed, 28 Jul 2021 09:53:44 +0800 Subject: [PATCH] =?UTF-8?q?:memo:=20=E4=BF=AE=E5=A4=8D=20twitter=20?= =?UTF-8?q?=E5=B9=B3=E5=8F=B0=E6=97=A0=E6=B3=95=E8=8E=B7=E5=8F=96=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E9=82=AE=E7=AE=B1=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../me/zhyd/oauth/config/AuthDefaultSource.java | 2 +- .../me/zhyd/oauth/request/AuthTwitterRequest.java | 14 ++++++-------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/main/java/me/zhyd/oauth/config/AuthDefaultSource.java b/src/main/java/me/zhyd/oauth/config/AuthDefaultSource.java index c471da7..ea99d3d 100644 --- a/src/main/java/me/zhyd/oauth/config/AuthDefaultSource.java +++ b/src/main/java/me/zhyd/oauth/config/AuthDefaultSource.java @@ -744,7 +744,7 @@ public enum AuthDefaultSource implements AuthSource { @Override public String userInfo() { - return "https://api.twitter.com/1.1/users/show.json"; + return "https://api.twitter.com/1.1/account/verify_credentials.json"; } }, diff --git a/src/main/java/me/zhyd/oauth/request/AuthTwitterRequest.java b/src/main/java/me/zhyd/oauth/request/AuthTwitterRequest.java index 7275a3c..5968a07 100644 --- a/src/main/java/me/zhyd/oauth/request/AuthTwitterRequest.java +++ b/src/main/java/me/zhyd/oauth/request/AuthTwitterRequest.java @@ -1,7 +1,6 @@ package me.zhyd.oauth.request; import com.alibaba.fastjson.JSONObject; -import me.zhyd.oauth.utils.HttpUtils; import com.xkcoding.http.constants.Constants; import com.xkcoding.http.support.HttpHeader; import com.xkcoding.http.util.MapUtil; @@ -11,6 +10,7 @@ import me.zhyd.oauth.model.AuthCallback; import me.zhyd.oauth.model.AuthToken; import me.zhyd.oauth.model.AuthUser; import me.zhyd.oauth.utils.GlobalAuthUtils; +import me.zhyd.oauth.utils.HttpUtils; import me.zhyd.oauth.utils.UrlBuilder; import java.util.HashMap; @@ -47,7 +47,7 @@ public class AuthTwitterRequest extends AuthDefaultRequest { */ @Override public String authorize(String state) { - AuthToken token = this.getRequestToken(); + AuthToken token = this.getRequestToken(); return UrlBuilder.fromBaseUrl(source.authorize()) .queryParam("oauth_token", token.getOauthToken()) .build(); @@ -119,17 +119,15 @@ public class AuthTwitterRequest extends AuthDefaultRequest { @Override protected AuthUser getUserInfo(AuthToken authToken) { Map queryParams = new HashMap<>(5); - queryParams.put("user_id", authToken.getUserId()); - queryParams.put("screen_name", authToken.getScreenName()); queryParams.put("include_entities", Boolean.toString(true)); + queryParams.put("include_email", Boolean.toString(true)); Map oauthParams = buildOauthParams(); oauthParams.put("oauth_token", authToken.getOauthToken()); Map params = new HashMap<>(oauthParams); params.putAll(queryParams); - oauthParams.put("oauth_signature", generateTwitterSignature(params, "GET", source.userInfo(), config.getClientSecret(), authToken - .getOauthTokenSecret())); + oauthParams.put("oauth_signature", generateTwitterSignature(params, "GET", source.userInfo(), config.getClientSecret(), authToken.getOauthTokenSecret())); String header = buildHeader(oauthParams); HttpHeader httpHeader = new HttpHeader(); @@ -147,6 +145,7 @@ public class AuthTwitterRequest extends AuthDefaultRequest { .blog(userInfo.getString("url")) .location(userInfo.getString("location")) .avatar(userInfo.getString("profile_image_url")) + .email(userInfo.getString("email")) .source(source.toString()) .token(authToken) .build(); @@ -155,9 +154,8 @@ public class AuthTwitterRequest extends AuthDefaultRequest { @Override protected String userInfoUrl(AuthToken authToken) { return UrlBuilder.fromBaseUrl(source.userInfo()) - .queryParam("user_id", authToken.getUserId()) - .queryParam("screen_name", authToken.getScreenName()) .queryParam("include_entities", true) + .queryParam("include_email", true) .build(); } -- GitLab