Note that there are some explanatory texts on larger screens.

plurals
  1. POI am unable to use Reddit's APIs to log in
    primarykey
    data
    text
    <p>I'm trying to use the Reddit API to do some stuff. I have everything working but changing pages and logging in.</p> <p>I need to login to use my program, I know how to use the cookie I get, but I just can't manage to login.</p> <p>Here's the code:</p> <pre><code>public static Login POST(URL url, String user, String pw) throws IOException { String encodedData = URLEncoder.encode("api_type=json&amp;user=" + user +"&amp;passwd="+pw, "UTF-8"); HttpURLConnection ycConnection = null; ycConnection = (HttpURLConnection) url.openConnection(); ycConnection.setRequestMethod("POST"); ycConnection.setDoOutput(true); ycConnection.setUseCaches (false); ycConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); PrintWriter out = new PrintWriter(ycConnection.getOutputStream()); out.print(encodedData.getBytes()); out.close(); BufferedReader in = new BufferedReader(new InputStreamReader(ycConnection.getInputStream())); String response = in.readLine(); Map&lt;String, List&lt;String&gt;&gt; headers = ycConnection.getHeaderFields(); List&lt;String&gt; values = headers.get("Set-Cookie"); String cookieValue = null; for (java.util.Iterator&lt;String&gt; iter = values.iterator(); iter.hasNext(); ) { String v = iter.next(); if (cookieValue == null) cookieValue = v; else cookieValue = cookieValue + ";" + v; } return new Login(cookieValue, response); } </code></pre> <p>The most typical exception I get is:</p> <blockquote> <p>java.io.IOException: Server returned HTTP response code: 504 for URL: <a href="http://www.reddit.com/api/login/kagnito/" rel="noreferrer">http://www.reddit.com/api/login/kagnito/</a> at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)</p> </blockquote> <p>But I have also received a lot of "invalid password" messages.</p> <p>How might I resolve this? Been at it for hours!</p> <p>Btw. This is what I'm having trouble understanding: <a href="https://github.com/reddit/reddit/wiki/API%3A-login" rel="noreferrer">https://github.com/reddit/reddit/wiki/API%3A-login</a> I'm not sure how to POST this? Should it go into the header, or ? I'm not that familiar with the HTTP protocol. (Hence my project - I'm learning)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload