3

我正在尝试使用 Reddit API 访问我的 Reddit 用户的帐户-其 API 页面上列出的POST 登录端点。

我试过这个:

curl -i -X POST -d '{"user":"myusername", "passwd":"mypassword", "rem":"true" }' http://www.reddit.com/api/login

但它说密码错误(我使用相同的凭据登录网站,所以我不知道出了什么问题):

HTTP/1.1 200 OK
Content-Type: application/json; charset=UTF-8
{
    "jquery": 
             [[0, 1, "call", ["body"]], [1, 2, "attr", "find"], 
              [2, 3, "call", [".status"]], [3, 4, "attr", "hide"], 
              [4, 5, "call", []],  [5, 6, "attr", "html"], 
              [6, 7, "call", [""]], [7, 8, "attr", "end"], 
              [8, 9, "call", []], [0, 10, "attr", "find"], 
              [10, 11, "call", [".error.WRONG_PASSWORD.field-passwd"]], 
              [11, 12, "attr", "show"], [12, 13, "call", []], 
              [13, 14, "attr", "text"], [14, 15, "call", ["invalid password"]], 
              [15, 16, "attr", "end"], [16, 17, "call", []]]
 }

但是,这有效:

curl -i -c Cookie.txt -d '{"user":"myusername", "passwd":"mypassword" , "rem":"true"}' http://www.reddit.com/api/login

产量:

{
     "jquery": 
              [[0, 1, "call", ["body"]], 
               [1, 2, "attr", "find"], 
               [2, 3, "call", [".status"]], 
               [3, 4, "attr", "hide"], 
               [4, 5, "call", []], 
               [5, 6, "attr", "html"], 
               [6, 7, "call", [""]], 
               [7, 8, "attr", "end"], 
               [8, 9, "call", []], 
               [0, 10, "attr", "find"], 
               [10, 11, "call", [".error.RATELIMIT.field-vdelay"]], 
               [11, 12, "attr", "show"], 
               [12, 13, "call", []], 
               [13, 14, "attr", "text"], 
               [14, 15, "call", 
                 ["you are doing that too much. try again in 4 minutes."]],
               [15, 16, "attr", "end"], [16, 17, "call", []]]
}

这也适用:

curl -b Cookie.txt http://www.reddit.com/api/me.json

问题:

  • 有谁知道如何使用 Reddit API 登录 Reddit?

  • 有没有更简单的方法通过 HTTP Post 传递凭据以正确登录?

  • 为什么它从我的初始卷曲中显示无效密码?

4

1 回答 1

14

以下是如何使用 curl 登录 reddit 的正确示例:

curl -duser=USERNAME -dpasswd=PASSWORD -dapi_type=json https://ssl.reddit.com/api/login

通过传递,api_type=json您可以获得有意义的 json 输出,而不是基于 reddit 的特定 jquery 输出。

{"json": {"errors": [],
          "data": {"modhash": "<REMOVED>",
                   "cookie": "<REMOVED>"}
         }
}

Note that reddit also properly uses the set-cookie header so that a proper http client / library will take advantage of the session for subsequent requests.

Your example did not work because you were not properly sending the form parameters. The example that you thought might have worked, in-fact did not. You were receiving a rate-limit response for failing to login too many times.

于 2013-03-02T00:59:50.223 回答