简体   繁体   中英

Reddit submit API 500 error

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM