如何使用Reddit的API登录? [英] How to login using Reddit's API?
问题描述
我想使用 Reddit API - POST登录端点访问我的Reddit用户帐户>在其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 ,
[4,5],
[2,3],call,[.status]],[3,4,attr ,[5],[5],[5],[5],[6],[ ],
[8,9,call,[]],[0,10,attr,find],
[10,11,call .WRONG_PASSWORD.field-passwd]],
[11,12,attr,show],[12,13,call,[]],
[ attr,text],[14,15,call,[invalid password]],
[15,16,attr,end],[16,17,然而,这个工作方式:
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]] ,4,attr,hide],
[4,5,call,[]],
[5,6,attr,html],
[6,7,call,[]],
[7,8,attr,end],
[ ,
[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,
[你做的太多了。请在4分钟后再试一次。]]],
[15,16,attr,end],[16,17,call,[]]]
}
这也同样适用:
code> curl -b Cookie.txt http://www.reddit.com/api/me.json
问题:
-
有没有人知道如何使用Reddit API登录Reddit?
/ li>
-
是否有更简单的方式可以通过HTTP Post正确传送凭证?
-
示例如何使用curl登录到reddit:
curl -duser = USERNAME -dpasswd = PASSWORD -dapi_type = json https: //ssl.reddit.com/api/login
通过传递 api_type =
{jsonjson :{errors:[],
data:{modhash:< REMOVED>,
cookie:< REMOVED>}
} $请注意,reddit也正确地使用了set-cookie头,这样一个合适的http客户端/ library将利用会话来处理后续请求。
您的示例无效,因为您没有正确发送表单参数。你认为可能工作的例子,事实上没有。您无法登入的次数太少,因此系统收到了限制回应。
Am trying to access my Reddit user's account by using the Reddit API - POST login Endpoint listed on its API page.
I tried this:
curl -i -X POST -d '{"user":"myusername", "passwd":"mypassword", "rem":"true" }' http://www.reddit.com/api/login
But it said wrong password (I logged into the website with the same credentials so I don't know what's wrong):
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", []]]
}
However, this works:
curl -i -c Cookie.txt -d '{"user":"myusername", "passwd":"mypassword" , "rem":"true"}' http://www.reddit.com/api/login
Yields:
{
"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", []]]
}
This also works as well:
curl -b Cookie.txt http://www.reddit.com/api/me.json
Questions:
Does anyone know how to login to Reddit using the Reddit API?
Is there an easier way to pass credentials via an HTTP Post to login correctly?
Why does it say invalid password from my initial curl?
解决方案 The following is a proper example of how to use curl to login to reddit:
curl -duser=USERNAME -dpasswd=PASSWORD -dapi_type=json https://ssl.reddit.com/api/login
By passing api_type=json
you get meaningful json output rather than reddit-specific jquery based output.
{"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.
这篇关于如何使用Reddit的API登录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!