Reddit submit API 500 error
Asked Answered
B

1

1

I'm attempting to use the reddit API to make posts, but the server is returning 500 errors.

For example, I tried posting to this URL with my cookie set:

http://www.reddit.com/api/submit?title=testtitle&sr=compsci&uh=<modhash_goes_here>&text=testtext&kind=self

And my Chrome Dev Tools prints the following error:

POST <my long URL goes here> 500 (Internal Server Error)

I read somewhere on StackOverflow that you need both the modhash and the cookie, so that's what I'm using. I tried without the modhash, and I tried with the superfluous "r=subreddit" parameter listed on Apigee. Neither helped.

Why would I be getting a 500 error?

Bipropellant answered 2/7, 2012 at 21:19 Comment(1)
a 500 level error is a server error, which suggests to me that there's something wrong with the code that executes when you make this API call.Counterintelligence
B
0

You're not supposed to POST data in the URL; you set the data in the POST object, and the POST that.... Which makes sense, because you POST things like passwords. For example (using jQuery):

$.post('http://www.reddit.com/api/vote',
        {
          'id' : 't3_' + id,
          'dir': dir,
          'uh' : mod_hash
        },
        function(data) {
            var err = false;
            for (var i in data) {
                if (data.hasOwnProperty(i)) {
                    err = true;
                    break;
                }
            }

            // No error!
            callback(err);
        });

URLs just happen to work for some reddit API calls because they implemented them on GET in addition to POST.

Bipropellant answered 5/9, 2012 at 1:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.