Jump to content

PasteBin API & WinHttp.au3


Recommended Posts

I am trying to create a UDF usign the PasteBin API >> http://pastebin.com/api.php but the example below doesn't seem to be returning the URL. If someone knows what the problem is this would be very much appreciated. Thanks.

This is what I have so far...

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6

#include "WinHttp.au3"

Opt("MustDeclareVars", 1)

; Initialize and get session handle
Global $hOpen = _WinHttpOpen()
; Get connection handle
Global $hConnect = _WinHttpConnect($hOpen, "http://www.pastebin.com/api.php")
; Make a request
Global $hRequest = _WinHttpSimpleSendRequest($hConnect, "POST", Default, Default, "paste_code=ExampleText")

If $hRequest Then
    ; Simple-read...
    ConsoleWrite(_WinHttpSimpleReadData($hRequest) & @CRLF)
    MsgBox(64, "Okay do!", "Returned source is print to concole. Check it.")
Else
    MsgBox(48, "Error", "Error ocurred for _WinHttpSimpleSendRequest, Error number is " & @error)
EndIf

; Close handles
_WinHttpCloseHandle($hRequest)
_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hOpen)

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

Just go for the head:

$hOpen = _WinHttpOpen()
$hConnect = _WinHttpConnect($hOpen, "www.pastebin.com")
$sRead = _WinHttpSimpleFormFill($hConnect, "api_form.php", Default, "name:paste_code", "Some string")
_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hOpen)

ConsoleWrite($sRead & @CRLF)

You would need new UDF (wait few hours) or apply the fix from the thread yourself ().

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

Cheers :x I saw that post but didn't think it applied to me. I have edited the UDF and used your version and as I predicted it worked. Thanks trancexx!

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

And without formfill:

#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6

#include "WinHttp.au3"

Opt("MustDeclareVars", 1)

; Initialize and get session handle
Global $hOpen = _WinHttpOpen("Simple Paste Client")
; Get connection handle
Global $hConnect = _WinHttpConnect($hOpen, "pastebin.com")


; Simple-request it...
Global $sData = "paste_code=" & _URIEncode("My Code") & "&paste_expire_date=1M"
Global $sResult = _WinHttpSimpleRequest($hConnect, "POST", "/api_public.php", $WINHTTP_NO_REFERER, $sData, "Content-Type: application/x-www-form-urlencoded")
ConsoleWrite($sResult & @CRLF)

; Close handles
_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hOpen)



Func _URIEncode($string)
    Local $u = StringLen($string)
    Local $a = StringToASCIIArray($string, 0, $u, 2)
    $string = ''
    For $i = 0 To $u-1
        Switch $a[$i]
            Case 45, 46, 48 To 57, 65 To 90, 95, 97 To 122, 126
                $string &= Chr($a[$i])
            Case 32
                $string &= "+"
            Case Else
                $string &= "%" & Hex($a[$i],2)
        EndSwitch
    Next
    Return $string
EndFunc

Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

Wow ProgAndy! Thanks to you too. That works perfect as well and now I have a better understanding of WinHttp.au3

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

Just used this Global $sData = "paste_code=" & _URIEncode("My Code") & "&paste_expire_date=10M&paste_format=AutoIt" and it works apart from the Expiry is still Never, which is the same in your Example too, weird. No Biggy! :x

Edited by guinness

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

For me, paste_expire_date works. Just use 10M and check the link after 10-15Minutes and its gone. You just can't see how long a paste will be stored on the page.

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

Ah, cool. I know it wasn't your code because I checked the API Form and the same thing happened. Cheers for clarifying. :x

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

  • 1 year later...

Hello,

updated api.

Resultant Paste : http://pastebin.com/FhQaxRMg

#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6

#include "WinHttp.au3"

Opt("MustDeclareVars", 1)
; Initialize and get session handle
Global $hOpen = _WinHttpOpen("Simple Paste Client")
; Get connection handle
Global $hConnect = _WinHttpConnect($hOpen, "pastebin.com")

Global $api_dev_key = ''; // your api_developer_key *NEEDED*
Global $api_paste_code = "testing autoit with pastebin's new API"; // your paste text
Global $api_paste_private = '0'; // 0=public 1=unlisted 2=private
Global $api_paste_name = 'UDF Autoit Test'; // name or title of your paste
Global $api_paste_expire_date = 'N';
Global $api_paste_format = 'php';
Global $api_user_key = ''; // if an invalid api_user_key or no key is used, the paste will be create as a guest
$api_paste_name = _URIEncode($api_paste_name);
$api_paste_code = _URIEncode($api_paste_code);

Global $sData='api_option=paste&api_user_key='&$api_user_key&'&api_paste_private='&$api_paste_private&'&api_paste_name='&$api_paste_name&'&api_paste_expire_date='&$api_paste_expire_date&'&api_paste_format='&$api_paste_format&'&api_dev_key='&$api_dev_key&'&api_paste_code='&$api_paste_code&''
; Simple-request it...
;~ Global $sData = "paste_code=" & _URIEncode("My Code") & "&paste_expire_date=1M"
Global $sResult = _WinHttpSimpleRequest($hConnect, "POST", "/api/api_post.php", $WINHTTP_NO_REFERER, $sData, "Content-Type: application/x-www-form-urlencoded")
ConsoleWrite($sResult & @CRLF)

; Close handles
_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hOpen)


Func _URIEncode($string)
Local $u = StringLen($string)
Local $a = StringToASCIIArray($string, 0, $u, 2)
$string = ''
For $i = 0 To $u-1
     Switch $a[$i]
         Case 45, 46, 48 To 57, 65 To 90, 95, 97 To 122, 126
             $string &= Chr($a[$i])
         Case 32
             $string &= "+"
         Case Else
             $string &= "%" & Hex($a[$i],2)
     EndSwitch
Next
Return $string
EndFunc
Edited by deltarocked
Link to comment
Share on other sites

deltarocked,

Thanks for the update. I take it this works with V3.1 of the API?

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

More Update. I think its final version, unless Pastebin changes its API.

NOTE 1: PasteBin has a rate limit of 20 pastes every 24 hrs. Hence, honor it.

NOTE 2: You will need username / password - login into pastebin and create one for yourself (DO NOT USE OAUTH based service - this code will not work)

NOTE 3: After Login click on "API" over here you will find your Developers API key

using this code, one can create a lot of things for pastebin. just take a look at their API examples they are simple to convert into autoit.

#region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 5 -w 6
#endregion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include "WinHttp.au3"

AutoItSetOption("MustDeclareVars", 1)
Global $hConnect, $hOpen, $Posturl
Local $api_dev_key, $sResult
Paste_Open();ok
$api_dev_key = _PasteBin_Init()
$sResult = _PasteBin_Go('Testing for Auto', 'Test', $api_dev_key)
ConsoleWrite($sResult & @CRLF)
Paste_Close()

Func _PasteBin_Go($api_paste_code, $api_paste_name, $api_dev_key)
Local $sResult
Local $api_paste_private = '0'; // 0=public 1=unlisted 2=private
Local $api_paste_expire_date = '10M';
Local $api_paste_format = 'php';
Local $api_user_key = ''; // if an invalid api_user_key or no key is used, the paste will be create as a guest
$api_paste_code = "testing autoit with pastebin's new API"; // your paste text
$api_paste_name = 'UDF Autoit Test'; // name or title of your paste
$api_user_key = Paste_User_Key($api_dev_key)
$sResult = Paste_Post($api_dev_key, $api_paste_code, $api_paste_private, $api_paste_name, $api_paste_expire_date, $api_paste_format, $api_user_key)
Return $sResult
EndFunc ;==>_PasteBin_Go

Func _PasteBin_Init()
Local $api_dev_key
$api_dev_key = IniRead('pastebin.ini', 'pastebin', 'api_dev_key', 0)
If $api_dev_key == 0 Or StringInStr($api_dev_key, 'invalid login', 0) > 0 Then
$api_dev_key = InputBox("Pastebin.com", "Please provide the API_Dev_Key", "", " M")
Select
Case @error = 0 ;OK - The string returned is valid
IniWrite('pastebin.ini', 'pastebin', 'api_dev_key', $api_dev_key)
Case @error = 1 ;The Cancel button was pushed
Exit
Case @error = 3 ;The InputBox failed to open
Exit
EndSelect
EndIf
Return $api_dev_key
EndFunc ;==>_PasteBin_Init

Func Paste_Post($api_dev_key, $api_paste_code, $api_paste_private, $api_paste_name, $api_paste_expire_date, $api_paste_format, $api_user_key)
Local $sData, $sResult, $Posturl
$Posturl = 'api/api_post.php'
$api_paste_name = _URIEncode($api_paste_name);
$api_paste_code = _URIEncode($api_paste_code);
$sData = 'api_option=paste&api_user_key=' & $api_user_key & '&api_paste_private=' & $api_paste_private & '&api_paste_name=' & $api_paste_name & '&api_paste_expire_date=' & $api_paste_expire_date & '&api_paste_format=' & $api_paste_format & '&api_dev_key=' & $api_dev_key & '&api_paste_code=' & $api_paste_code
$sResult = _WinHttpSimpleRequest($hConnect, "POST", $Posturl, $WINHTTP_NO_REFERER, $sData, "Content-Type: application/x-www-form-urlencoded")
Return $sResult
EndFunc ;==>Paste_Post

Func Paste_User_Key($api_dev_key)
Local $sData, $sResult, $Posturl, $api_user_name, $api_user_password
$sResult = IniRead('pastebin.ini', 'pastebin', 'api_user_key', '0')
If $sResult == 0 Then
$api_user_name = IniRead('pastebin.ini', 'pastebin', 'api_user_name', '0')
$api_user_password = IniRead('pastebin.ini', 'pastebin', 'api_user_password', '0')
If $api_user_name == 0 Or $api_user_password == 0 Then
$api_user_name = InputBox("Pastebin.com", "Please provide the Pastebin Username", "", " M")
Select
Case @error = 0 ;OK - The string returned is valid
IniWrite('pastebin.ini', 'pastebin', 'api_user_name', $api_user_name)
Case @error = 1 ;The Cancel button was pushed
Exit
Case @error = 3 ;The InputBox failed to open
Exit
EndSelect
$api_user_password = InputBox("Pastebin.com", "Please provide the Pastebin Password", "", " M")
Select
Case @error = 0 ;OK - The string returned is valid
IniWrite('pastebin.ini', 'pastebin', 'api_user_password', $api_user_password)
Case @error = 1 ;The Cancel button was pushed
Exit
Case @error = 3 ;The InputBox failed to open
Exit
EndSelect
EndIf
$Posturl = 'api/api_login.php'
$api_user_name = _URIEncode($api_user_name)
$api_user_password = _URIEncode($api_user_password)
$sData = 'api_dev_key=' & $api_dev_key & '&api_user_name=' & $api_user_name & '&api_user_password=' & $api_user_password & ''
$sResult = _WinHttpSimpleRequest($hConnect, "POST", $Posturl, $WINHTTP_NO_REFERER, $sData, "Content-Type: application/x-www-form-urlencoded")
If StringLen($sResult) == 32 Then
IniWrite('pastebin.ini', 'pastebin', 'api_user_key', $sResult)
Else
Exit
EndIf
EndIf
Return $sResult
EndFunc ;==>Paste_User_Key

Func Paste_Open()
$hOpen = _WinHttpOpen("Simple Paste Client")
$hConnect = _WinHttpConnect($hOpen, "pastebin.com")
EndFunc ;==>Paste_Open

Func Paste_Close()
_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hOpen)
EndFunc ;==>Paste_Close

Func _URIEncode($string)
Local $u = StringLen($string)
Local $a = StringToASCIIArray($string, 0, $u, 2)
$string = ''
For $i = 0 To $u - 1
Switch $a[$i]
Case 45, 46, 48 To 57, 65 To 90, 95, 97 To 122, 126
$string &= Chr($a[$i])
Case 32
$string &= "+"
Case Else
$string &= "%" & Hex($a[$i], 2)
EndSwitch
Next
Return $string
EndFunc ;==>_URIEncode
Edited by deltarocked
Link to comment
Share on other sites

  • 4 years later...

Hi,

I don't want to revive a zombie but this (and another https://www.autoitscript.com/forum/topic/150838-pastebin-udf/#comment-1078099) thread is the only one dealing with pastebin.

There is something new. The api is working with ssl only since august 1st. So you must change the winhttp requests.

 

Regards, Conrad

 

SciTE4AutoIt = 3.7.3.0   AutoIt = 3.3.14.2   AutoItX64 = 0   OS = Win_10   Build = 19044   OSArch = X64   Language = 0407/german
H:\...\AutoIt3\SciTE     H:\...\AutoIt3      H:\...\AutoIt3\Include     (H:\ = Network Drive)

   88x31.png  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...