I am trying to use the Reddit API to save a message. I know that I’m formatting the request incorrectly, but I can’t find the documentation on how to do this correctly. If someone can lead me in the right direction or help me format the request correctly. This is what I still have.
public void save(View v)
{
OkHttpClient client = new OkHttpClient();
String authString = MainActivity.CLIENT_ID + ":";
String encodedAuthString = Base64.encodeToString(authString.getBytes(),
Base64.NO_WRAP);
System.out.println("myaccesstoken is: "+ myaccesstoken);
System.out.println("the image id is: "+ myimageid);
Request request = new Request.Builder()
.addHeader("User-Agent", "Sample App")
.addHeader("Authorization", "Bearer " + myaccesstoken)
.addHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8")
.url("https://oauth.reddit.com/api/save.json?")
.post(RequestBody.create(MediaType.parse("application/x-www-form-urlencoded"),
""+ myimageid +
"1"))
.build();
client.newCall(request);
}
I am very new to using APIs and I don’t know exactly what I am looking for. Here is a link to the reddit API to save
https://www.reddit.com/dev/api/oauth#POST_api_save
Thank you in advance for your help!!!
source
share