提交 881a87ed 编写于 作者: 智布道's avatar 智布道 👁

📝 修复 twitter 平台无法获取用户邮箱的问题

上级 4c8fdbae
...@@ -744,7 +744,7 @@ public enum AuthDefaultSource implements AuthSource { ...@@ -744,7 +744,7 @@ public enum AuthDefaultSource implements AuthSource {
@Override @Override
public String userInfo() { public String userInfo() {
return "https://api.twitter.com/1.1/users/show.json"; return "https://api.twitter.com/1.1/account/verify_credentials.json";
} }
}, },
......
package me.zhyd.oauth.request; package me.zhyd.oauth.request;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import me.zhyd.oauth.utils.HttpUtils;
import com.xkcoding.http.constants.Constants; import com.xkcoding.http.constants.Constants;
import com.xkcoding.http.support.HttpHeader; import com.xkcoding.http.support.HttpHeader;
import com.xkcoding.http.util.MapUtil; import com.xkcoding.http.util.MapUtil;
...@@ -11,6 +10,7 @@ import me.zhyd.oauth.model.AuthCallback; ...@@ -11,6 +10,7 @@ import me.zhyd.oauth.model.AuthCallback;
import me.zhyd.oauth.model.AuthToken; import me.zhyd.oauth.model.AuthToken;
import me.zhyd.oauth.model.AuthUser; import me.zhyd.oauth.model.AuthUser;
import me.zhyd.oauth.utils.GlobalAuthUtils; import me.zhyd.oauth.utils.GlobalAuthUtils;
import me.zhyd.oauth.utils.HttpUtils;
import me.zhyd.oauth.utils.UrlBuilder; import me.zhyd.oauth.utils.UrlBuilder;
import java.util.HashMap; import java.util.HashMap;
...@@ -119,17 +119,15 @@ public class AuthTwitterRequest extends AuthDefaultRequest { ...@@ -119,17 +119,15 @@ public class AuthTwitterRequest extends AuthDefaultRequest {
@Override @Override
protected AuthUser getUserInfo(AuthToken authToken) { protected AuthUser getUserInfo(AuthToken authToken) {
Map<String, String> queryParams = new HashMap<>(5); Map<String, String> 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_entities", Boolean.toString(true));
queryParams.put("include_email", Boolean.toString(true));
Map<String, String> oauthParams = buildOauthParams(); Map<String, String> oauthParams = buildOauthParams();
oauthParams.put("oauth_token", authToken.getOauthToken()); oauthParams.put("oauth_token", authToken.getOauthToken());
Map<String, String> params = new HashMap<>(oauthParams); Map<String, String> params = new HashMap<>(oauthParams);
params.putAll(queryParams); params.putAll(queryParams);
oauthParams.put("oauth_signature", generateTwitterSignature(params, "GET", source.userInfo(), config.getClientSecret(), authToken oauthParams.put("oauth_signature", generateTwitterSignature(params, "GET", source.userInfo(), config.getClientSecret(), authToken.getOauthTokenSecret()));
.getOauthTokenSecret()));
String header = buildHeader(oauthParams); String header = buildHeader(oauthParams);
HttpHeader httpHeader = new HttpHeader(); HttpHeader httpHeader = new HttpHeader();
...@@ -147,6 +145,7 @@ public class AuthTwitterRequest extends AuthDefaultRequest { ...@@ -147,6 +145,7 @@ public class AuthTwitterRequest extends AuthDefaultRequest {
.blog(userInfo.getString("url")) .blog(userInfo.getString("url"))
.location(userInfo.getString("location")) .location(userInfo.getString("location"))
.avatar(userInfo.getString("profile_image_url")) .avatar(userInfo.getString("profile_image_url"))
.email(userInfo.getString("email"))
.source(source.toString()) .source(source.toString())
.token(authToken) .token(authToken)
.build(); .build();
...@@ -155,9 +154,8 @@ public class AuthTwitterRequest extends AuthDefaultRequest { ...@@ -155,9 +154,8 @@ public class AuthTwitterRequest extends AuthDefaultRequest {
@Override @Override
protected String userInfoUrl(AuthToken authToken) { protected String userInfoUrl(AuthToken authToken) {
return UrlBuilder.fromBaseUrl(source.userInfo()) return UrlBuilder.fromBaseUrl(source.userInfo())
.queryParam("user_id", authToken.getUserId())
.queryParam("screen_name", authToken.getScreenName())
.queryParam("include_entities", true) .queryParam("include_entities", true)
.queryParam("include_email", true)
.build(); .build();
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册