Reddit integration to android app

Deadly 提交于 2019-12-08 05:18:27

Ok, so I found a solution for this (maybe not a perfect one but it works).

So first of all download the raw4j reddit api wrapper https://github.com/corydissinger/raw4j

The submit a new link should be included pretty soon. But if you will download it and the submit function will not be pressent (I posted my changes to the developer of raw4j but don't know when he will update it) add these:

To "RedditApiParameterConstants.java" add these:

public static final String CAPTCHA_ANSWER       = "captcha";
public static final String EXTENSION            = "extension";
public static final String IDEN                 = "iden";
public static final String KIND                 = "kind";
public static final String RESUBMIT             = "resubmit";
public static final String SAVE                 = "save";
public static final String SEND_REPLIES         = "sendreplies";
public static final String SUB_REDDIT           = "sr";
public static final String THEN                 = "then";
public static final String TITLE                = "title";
public static final String URL                  = "url";

And to the "Reddit.java" add this:

 public RedditJsonMessage newSubmitt(String captchaResponse, String extension, String iden, String kind,
    boolean resubmit, boolean save, boolean sendreplies, String sub_reddit, String text, String then, String title, String url_to_post) throws RedditException {
final List<String> path = new ArrayList<String>(2);
final Map<String, String> form = new HashMap<String, String>(13);

path.add(RedditApiResourceConstants.API);
path.add(RedditApiResourceConstants.SUBMIT);

form.put(RedditApiParameterConstants.API_TYPE, RedditApiParameterConstants.JSON);
form.put(RedditApiParameterConstants.CAPTCHA_ANSWER, captchaResponse);
form.put(RedditApiParameterConstants.EXTENSION, extension);
form.put(RedditApiParameterConstants.IDEN, iden);
form.put(RedditApiParameterConstants.KIND, kind);
form.put(RedditApiParameterConstants.RESUBMIT, String.valueOf(resubmit));
form.put(RedditApiParameterConstants.SAVE, String.valueOf(save));
form.put(RedditApiParameterConstants.SEND_REPLIES, String.valueOf(sendreplies));
form.put(RedditApiParameterConstants.SUB_REDDIT, sub_reddit);
form.put(RedditApiParameterConstants.TEXT, text);
form.put(RedditApiParameterConstants.THEN, then);
form.put(RedditApiParameterConstants.TITLE, title);
form.put(RedditApiParameterConstants.URL, url_to_post);

final RedditRequestInput requestInput = new RedditRequestInput(path, null, form);
final RedditRequestResponse response = requestor.executePost(requestInput);
//System.out.println("Response From Reddit = " + response.toString());
final RedditJsonParser parser = new RedditJsonParser(response.getBody());
final RedditJsonMessage message = parser.parseJsonMessage();

if (!message.getErrors().isEmpty()){
    throw new RedditException("Got errors while submiting the link: " + message.toString());
}

return message;

}

And then just build the *.jar file (if it was not included) from that project and add it to your project.

Hope this will save some time for other developers.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!