0
我想通過Twitter的Rest API獲取用戶的一些信息,但總是得到400響應代碼(錯誤的請求)。Twitter Rest API Http請求失敗(Android)
TwitterAuthToken authToken = Twitter.getSessionManager().getActiveSession().getAuthToken();
OAuthSigning oauthSigning = new OAuthSigning(TwitterCore.getInstance().getAuthConfig(), authToken);
Map<String, String> authHeaders = oauthSigning.getOAuthEchoHeadersForVerifyCredentials();
try {
URL url = new URL("https://api.twitter.com/1.1/account/verify_credentials.json");
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
connection.setRequestMethod("GET");
for (Map.Entry<String, String> entry : authHeaders.entrySet()) {
connection.setRequestProperty(entry.getKey(), entry.getValue());
}
Log.v(MAIN_LOGIN_ACTIVITY_TAG, String.valueOf(connection.getResponseCode()));
} catch (IOException e) {
e.printStackTrace();
}
我一直在尋找在https://dev.twitter.com/es/twitter-kit/android/oauth-echo,好像是沒事...... 任何人都可以幫我嗎?
在此先感謝!