7

I know how to generate a user key using the pastebin API, but how can I use this userkey to access a raw private paste?

I am using Lua for this.

daxvena
  • 1,140
  • 3
  • 14
  • 30

3 Answers3

1

Obtaining the raw paste bin output is not part of of the Pastebin API:

This option is actually not part of our API, but you might still want to use it. To get the RAW output of a paste you can use our RAW data output URL:

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

Simply add the paste_key at the end of that URL and you will get the RAW output.

Since private pastes can only be seen by the user who created them, my guess is that they use the logincookie for authentication. In that case, you'll need to send it with the HTTP request.


In respect to implementing this in Lua, (since you haven't said which library you're using) I'm gonna go forth and recommend the HTTP module in LuaSocket or the wonderful Luvit (http://luvit.io).

MBlanc
  • 1,773
  • 15
  • 31
1

Here is a ready example of the code for you:

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
Mike V.
  • 2,077
  • 8
  • 19
0

I know that this is a little late to answer the question but I hope this will help someone later on.

If you want to access raw private pastes, you will first need to list the pastes that the user has created. This is a part of the API. This requires the user to be logged in.

With this API you can list all the pastes created by a certain user. You will need send a valid POST request to the URL below to access the data:

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

The response that you will get will be an XML response, as follows:

<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>  

Once you have that, parse the XML to get the paste_key and the paste_private. You need to check the value of paste_private because you want private pastes only. The documentation says:

We have 3 valid values available which you can use with the 'api_paste_private' parameter:

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)  

So, if your paste has paste_private set to 2, get the paste_key for it.

Once you have the paste_key, use the API call to get the RAW paste. No username or password required once you have the paste key for the private paste.

Have fun!

An SO User
  • 24,612
  • 35
  • 133
  • 221