当我尝试检索访问令牌获取429:Too Many Requests错误时,我已按照链接中提到的步骤进行操作 - > https://github.com/reddit/reddit/wiki/OAuth2
错误的原因可能是什么。我的代码是。
public static void main (String[] args) throws Exception
{
String url3 ="https://www.reddit.com/api/v1/access_token?";
OAuthRequest get_info_request = new OAuthRequest(Verb.POST, url3);
get_info_request.setCharset("UTF-8");
get_info_request.addBodyParameter("grant_type", "authorization_code");
get_info_request.addBodyParameter("redirect_uri", "xxxxxxxxxx");
get_info_request.addBodyParameter("code", "xxxxxxxxx");
get_info_request.addBodyParameter("USER_AGENT", "desktop:net.dean.ayati:v0.9.0 (by /u/ayati)");
System.out.println(get_info_request.getCompleteUrl()+get_info_request.getBodyContents());
Response json_response = get_info_request.send();
System.out.println(json_response.getBody());
JSONObject jsonResp = new JSONObject(json_response.getBody());
System.out.println("is" + jsonResp);
}
答案 0 :(得分:1)
虽然HTTP标头不区分大小写,但您的 USER_AGENT 拼写错误。
它使用' - '而不是'_'。
尝试:
get_info_request.addBodyParameter("User-Agent", "desktop:net.dean.ayati:v0.9.0 (by /u/ayati)");
看看是否有效。