Reddit submit API 500 error

早过忘川 提交于 2019-12-23 03:39:16

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/11301342/reddit-submit-api-500-error

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