7

我知道如何使用 pastebin API 生成用户密钥,但如何使用此用户密钥访问原始私有粘贴?

我为此使用 Lua。

4

3 回答 3

1

获取原始粘贴箱输出不是粘贴箱API的一部分:

此选项实际上不是我们 API 的一部分,但您可能仍想使用它。要获取粘贴的 RAW 输出,您可以使用我们的 RAW 数据输出 URL:

http://pastebin.com/raw.php?i=

只需在该 URL 的末尾添加paste_key,您将获得 RAW 输出。

由于私有粘贴只能由创建它们的用户看到,我猜他们使用 logincookie 进行身份验证。在这种情况下,您需要将其与 HTTP 请求一起发送。


关于在 Lua 中实现这一点,(因为你没有说你正在使用哪个库)我会继续推荐 LuaSocket 中的HTTP 模块或精彩的 Luvit(http://luvit.io)。

于 2014-06-07T14:03:53.397 回答
1

这是为您准备的代码示例:

local https = require('ssl.https')
    https.TIMEOUT= 15

    local private_raw_url="https://pastebin.com/raw/YOURPAGE" -- Change raw link
    local user_name, user_password = "USER", "PASS"           -- and user with password

    local request_body = "submit_hidden=submit_hidden&user_name=".. user_name .. "&user_password=" .. user_password .. "&submit=Login"

    local resp = {}
    local res, code, headers, status = https.request ( {
                            method = 'POST',
                            url = "https://pastebin.com/login",
                            headers = { 
                              Host = "pastebin.com", 
                              ["Content-Type"] = "application/x-www-form-urlencoded",
                              ["Content-Length"] = string.len(request_body), 
                              Connection = "keep-alive",
                            }, 
                            source = ltn12.source.string(request_body),
                            sink = ltn12.sink.table(resp),
                            protocol =  "tlsv1", 
                            verify = "none",
                            verifyext = {"lsec_continue", "lsec_ignore_purpose"},
                            options = { "all", "no_sslv2", "no_sslv3" } 
                        } )
    if not headers['set-cookie']:find('pastebin_user') then 
           print('bad login')
           return
    end
    resp={}
    local cookie = headers['set-cookie'] or ''
    local cookie1, cookie2, cookie3 = cookie:match("(__cfduid=%w+; ).*(PHPSESSID=%w+; ).*(pastebin_user=%w+; )" )   
    if cookie1 and cookie2 and cookie3 then
            cookie = cookie1 .. cookie2 .. cookie3
            body, code, headers= https.request{
                url = private_raw_url ,
                headers = { 
                            --Host = "pastebin.com", 
                            ['Cookie'] = cookie,
                            ['Connection'] = 'keep-alive'
                                },         
                sink = ltn12.sink.table(resp)     
             }  

            if code~=200 then  return  end 

           print( table.concat(resp) )
    else
        print("error match cookies!" )
    end
于 2017-07-25T18:50:14.447 回答
0

我知道回答这个问题有点晚了,但我希望这对以后的人有所帮助。

如果要访问原始私有粘贴,您首先需要列出用户创建的粘贴。这是 API 的一部分。这需要用户登录。

使用此 API,您可以列出某个用户创建的所有粘贴。您需要向以下 URL 发送有效的 POST 请求才能访问数据:

http://pastebin.com/api/api_post.php  

您将获得的响应将是一个 XML 响应,如下所示:

<paste>
    <paste_key>0b42rwhf</paste_key>
    <paste_date>1297953260</paste_date>
    <paste_title>javascript test</paste_title>
    <paste_size>15</paste_size>
    <paste_expire_date>1297956860</paste_expire_date>
    <paste_private>0</paste_private>
    <paste_format_long>JavaScript</paste_format_long>
    <paste_format_short>javascript</paste_format_short>
    <paste_url>http://pastebin.com/0b42rwhf</paste_url>
    <paste_hits>15</paste_hits>
</paste>  

一旦你有了它,解析 XML 以获取paste_keypaste_private. 您需要检查 的值,paste_private因为您只需要私人粘贴。文档说:

我们有 3 个可用的有效值,您可以将其与 'api_paste_private' 参数一起使用:

0 = Public
1 = Unlisted
2 = Private (only allowed in combination with api_user_key, as you have to be logged into your account to access the paste)  

因此,如果您的粘贴已paste_private设置为2,请获取paste_key它。

获得 后paste_key,使用 API 调用获取 RAW 粘贴。拥有私人粘贴的粘贴密钥后,无需用户名或密码。

玩得开心!

于 2014-06-21T06:58:52.970 回答