Pastebin.com API

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
xZomBie
Posts: 256
Joined: 02 Oct 2013, 02:57

Pastebin.com API

14 Jan 2014, 04:57

Does anyone have any experience with APIs?
I don't understand the examples from Pastebin.com/api.
Can someone please explain it to me or if possible create a simple AHK script that can paste text from a variable into Pastebin.com? Thanks in advance.
User avatar
Blackholyman
Posts: 1293
Joined: 29 Sep 2013, 22:57
Facebook: socialjsz
Google: +Jszapp
Location: Denmark
Contact:

Re: Pastebin.com API

14 Jan 2014, 07:09

No time at the moment to explain but for now here is a function Example from RaptorX's Autohotkey Toolkit thats using a httpRequest function

Code: Select all

pasteUpload(mode=""){
    conf.load(script.conf), root:=conf.documentElement, options:=root.firstChild

    FormatTime,pb_time,,[MMM/dd/yyyy - HH:mm:ss]
    sci[5].GetText(sci[5].GetLength()+1,pb_code)
    node := options.selectSingleNode("//Codet/Pastebin")
    if (mode = "show"){
        Gui, 94: Show, NoActivate
        WinGetPos,,, 94Width, 94Height, ahk_id %$Hwnd94%
        WinMove, ahk_id %$Hwnd94%,, system.wa.Right,% system.wa.Bottom - 94Height
        pop_Right := system.wa.Right - 2
        Loop, 5
        {
            pop_Right -= 94Width/5
            WinMove, ahk_id %$Hwnd94%,,% pop_Right
        }
        Settimer, Sleep, % 1*sec    ; Using a timer allows to "stop" the sleep time fixing the bug with
                                    ; Ctrl + C not working some times.
        return

        Sleep:
            if slp = 5
            {
                slp:=0
                SetTimer, Sleep, Off
                Gui, 94: Hide       ; Hide Codet Popup
            } slp++
        return
    }
    if (mode = "auto")
        pb_ddl := options.selectSingleNode("//Codet/Pastebin/@current").text

    ; [httpRequest]{
    if (pb_ddl = "Autohotkey.net"){
            URL := "http://www.autohotkey.net/paste/"
            POST:= "MAX_FILE_SIZE=262144"
                .  "&jscheck=1"
                .  "&text=" uriSwap(mode = "auto" ? Clipboard : pb_code, "e")
                .  "&description=" uriSwap(mode = "auto" ? null : pb_description, "e")
                .  "&submit=Paste"
                .  "&author="
                .  uriSwap(mode = "auto"  ? options.selectSingleNode("//Pastebin/AutoHotkey/@nick").text
                                          : pb_name, "e")
                .  "&irc=" ; note that here 1 = public and 0 = private, contrary to how i save it, hence the not.
                .  (mode = "auto" ? !options.selectSingleNode("//Pastebin/AutoHotkey/@private").text
                                  : (pb_exposure = "Public" ? 1 : 0))
    }
    else if (pb_ddl = "Pastebin.com"){
        pb_expiration := mode = "auto" ? options.selectSingleNode("//Pastebin/PasteBin/@expiration").text
                                       : pb_expiration
        URL := "http://www.pastebin.com/api/api_post.php"
        POST:= "api_option=paste"
            .  "&api_dev_key=786f7529a54ee64a1959612f2aeb8596"
            .  "&api_paste_code=" uriSwap(mode = "auto" ? Clipboard : pb_code, "e")
            .  "&api_paste_private="
            .  (mode = "auto" ? options.selectSingleNode("//Pastebin/PasteBin/@private").text
                              : (pb_exposure = "Public" ? 0 : 1))
            .  "&api_paste_name=" uriSwap(pb_name, "e")
            .  "&api_paste_format=autohotkey"
            .  "&api_paste_expire_date=" pb_expiration := (pb_expiration = "Never" ? "N"
                                                       :   pb_expiration = "10 Minutes" ? "10M"
                                                       :   pb_expiration = "1 Hour" ? "1H"
                                                       :   pb_expiration = "1 Day" ? "1D"
                                                       :   pb_expiration = "1 Month" ? "1M" : null)
    }

    httpRequest(URL,POST,headers:="", "charset: utf-8")
    RegexMatch(POST, "i)<title>Paste #(.*?)<\/title>|.com\/(.*)", pb_url)
    pb_url := (pb_ddl = "Pastebin.com" ? substr(URL, 1,24) : URL) pb_url1 pb_url2
    Tooltip, % "Copied: " Clipboard := pb_url, 5, 5
    SetTimer, ttOff, % "-" 5 * sec

    if (mode = "auto")
        SoundPlay, *48
    ;}


    Loop, parse, pb_code, `n, `r%a_space%%a_tab%
    {
        if a_index = 5
            break
        pb_preview .= pb_preview ? "[``n]" a_loopfield : "`n" a_loopfield
    }

    node := options.selectSingleNode("//Codet/History")
    if node.childNodes.length = node.attributes.item[0].text
        node.removeChild(node.firstChild)

    _h := conf.createElement("paste"), _h.setAttribute("time", pb_time), _h.setAttribute("url", pb_url)
    _h.text := pb_preview "`n                ", pb_preview := "" ; for xml formatting
    node.appendChild(_h)
    conf.transformNodeToObject(xsl, conf)
    conf.save(script.conf), conf.load(script.conf), root:=options:=_h:=null
    return

    ttOff:
        Tooltip
    return
}
Also check out:
Courses on AutoHotkey

My Autohotkey Blog
:dance:
User avatar
Avi
Posts: 193
Joined: 30 Sep 2013, 09:51
Facebook: avi.aryan.ap
Google: +AviAryan
GitHub: aviaryan
Location: India
Contact:

Re: Pastebin.com API

15 Jan 2014, 07:09

I had worked on a Pastebin API earlier but I never released it.
Here is the link ( https://github.com/avi-aryan/totalpaste ... BinApi.ahk ) .
This code pastes on Pastebin

Code: Select all

pbin := new pastebin()
msgbox % Clipboard := pbin.pasteAsGuest("some text to paste", "paste_name", "autohotkey")
The API is complete with respect to their documentation. It should work well.
Writes at Dev Letters

Clipjump Clipboard Manager : More Scripts (updated 2019)

Image
User avatar
xZomBie
Posts: 256
Joined: 02 Oct 2013, 02:57

Re: Pastebin.com API

15 Jan 2014, 09:52

Thanks guys for the codes. Will try them when I have time. I'm actually trying to create a Pastebin desktop tool, but don't understand the examples on Pastebin.com/api which uses cURL that I totally don't have any knowledge about :?
User avatar
labrint
Posts: 369
Joined: 14 Jun 2017, 05:06
Facebook: https://www.facebook.com/agiusjohn/
Location: Malta

Re: Pastebin.com API

14 Nov 2017, 06:58

Below is an example of how to post on PASTEBIN as a registered user;

This is also useful for someone who needs to make HTTP Requests (Query, GET, POST methods) to other website's API. It is very simple to use and straightforward to understand.

Code: Select all

; Replace "***" with your own details (there are 4 *** in the param below, replace them all)

param := "api_dev_key=***&api_paste_code=Check it out this is an autohotkey test!&api_paste_private=1&api_paste_name=Autohotkey Test&api_paste_expire_date=N&api_option=paste&api_user_name=***&api_user_password=***&api_user_key=***"
str =https://pastebin.com/api/api_post.php

msgbox, % url_tovar(str, param)

url_tovar(URL, param) { 
    WebRequest := ComObjCreate("WinHttp.WinHttpRequest.5.1")
    WebRequest.Open("POST", URL)
	WebRequest.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded")
    WebRequest.Send(param)
    res := WebRequest.ResponseText
    return res
}
Getting your Dev Key (api_dev_key);

Go to https://pastebin.com/api and find the section "Your Unique Developer API Key". Your dev key is listed here.

Getting your User Key (api_dev_key);

Go to https://pastebin.com/api/api_user_key.html. Enter your username and password and click "create api_user_key"

Unfortunately it is NOT possible to Edit pastebin pastes using Http Requests.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], Spawnova, wetware05 and 48 guests