如何登录使用reddit的的API?(How to login using Reddit's

2019-08-17 02:22发布

我试图通过访问我的reddit的用户的帐户reddit的API -登录后端点的API页面上列出。

我尝试这样做:

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将凭据传递正确地注册一个更简单的方法?

  • 为什么它说从我最初的卷曲无效的密码?

Answer 1:

以下是如何使用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>"}
         }
}

需要注意的是书签交易也正常使用set-cookie头,这样一个恰当的HTTP客户端/库将采取后续请求的会话的优势。

您的例子不工作,因为你没有正确发送表单参数。 你认为这个例子可能已经工作过,在-其实没有。 你被接收速率限制响应未能登录次数过多。



文章来源: How to login using Reddit's API?