Tag: reddit

如何在Android中正确解析Reddit API

所以我一直在尝试解析Reddits r / hot / .json API以获取主题信息的列表视图,但我似乎无法使我的JSON正确。 我到处寻找,我似乎找不到如何为reddit做这个的好例子。 这是我到目前为止… JSONObject response = new JSONObject(result); JSONObject data = response.getJSONObject(“data”); JSONArray hotTopics = data.getJSONArray(“children”); for(int i=0; i<hotTopics.length(); i++) { JSONObject topic = hotTopics.getJSONObject(i); String author = topic.getString("author"); String imageUrl = topic.getString("thumbnail"); String postTime = topic.getString("created_utc"); String rScore = topic.getString("score"); String title = topic.getString("title"); topicdata.add(new ListData(title, author, imageUrl, […]

我无法使用Reddit的API登录

我正在尝试使用Reddit API来做一些事情。 我有一切工作,但更改页面和登录。 我需要登录才能使用我的程序,我知道如何使用我得到的cookie,但我无法登录。 这是代码: public static Login POST(URL url, String user, String pw) throws IOException { String encodedData = URLEncoder.encode(“api_type=json&user=” + user +”&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 […]