Reputation: 33
When am trying to retrieve the access token getting 429 :Too Many Requests error,i have followed the steps mentioned in the link --> https://github.com/reddit/reddit/wiki/OAuth2
what could be the reason for the error .here is my code.
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);
}
Upvotes: 1
Views: 557
Reputation: 6667
While HTTP headers are case-insensitive you still have USER_AGENT spelt incorrectly.
It uses a '-' not '_' in it.
Try:
get_info_request.addBodyParameter("User-Agent", "desktop:net.dean.ayati:v0.9.0 (by /u/ayati)");
and see if that works.
Upvotes: 1