Platforms to show: All Mac Windows Linux Cross-Platform

/CURL/WebServices/Twitter oAuth


Required plugins for this example: MBS CURL Plugin

You find this example project in your Plugins Download as a Xojo project file within the examples folder: /CURL/WebServices/Twitter oAuth

This example is the version from Wed, 3rd Jan 2023.

Project "Twitter oAuth.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Löschen"
Const kFileQuit = "Beenden"
Const kFileQuitShortcut = ""
End Class
Class MainWindow Inherits Window
Control Label1 Inherits Label
ControlInstance Label1 Inherits Label
End Control
Control ConsumerKey Inherits TextField
ControlInstance ConsumerKey Inherits TextField
End Control
Control Label2 Inherits Label
ControlInstance Label2 Inherits Label
End Control
Control Label3 Inherits Label
ControlInstance Label3 Inherits Label
End Control
Control ConsumerSecret Inherits TextField
ControlInstance ConsumerSecret Inherits TextField
End Control
Control RequestToken Inherits TextField
ControlInstance RequestToken Inherits TextField
End Control
Control Label4 Inherits Label
ControlInstance Label4 Inherits Label
End Control
Control Label5 Inherits Label
ControlInstance Label5 Inherits Label
End Control
Control RequestTokenSecret Inherits TextField
ControlInstance RequestTokenSecret Inherits TextField
End Control
Control Verifier Inherits TextField
ControlInstance Verifier Inherits TextField
End Control
Control Label6 Inherits Label
ControlInstance Label6 Inherits Label
End Control
Control RegisterButton Inherits PushButton
ControlInstance RegisterButton Inherits PushButton
EventHandler Sub Action() showurl "http://twitter.com/apps" End EventHandler
End Control
Control RequestButton Inherits PushButton
ControlInstance RequestButton Inherits PushButton
EventHandler Sub Action() GetRequestToken End EventHandler
End Control
Control LoadButton Inherits PushButton
ControlInstance LoadButton Inherits PushButton
EventHandler Sub Action() HTMLViewer1.loadurl "https://api.twitter.com/oauth/authorize?oauth_token=" + RequestToken.Text End EventHandler
End Control
Control AccessToken Inherits TextField
ControlInstance AccessToken Inherits TextField
End Control
Control Label7 Inherits Label
ControlInstance Label7 Inherits Label
End Control
Control Label8 Inherits Label
ControlInstance Label8 Inherits Label
End Control
Control AccessTokenSecret Inherits TextField
ControlInstance AccessTokenSecret Inherits TextField
End Control
Control AccessButton Inherits PushButton
ControlInstance AccessButton Inherits PushButton
EventHandler Sub Action() GetAccessToken End EventHandler
End Control
Control ScreenName Inherits TextField
ControlInstance ScreenName Inherits TextField
End Control
Control Label9 Inherits Label
ControlInstance Label9 Inherits Label
End Control
Control Message Inherits TextField
ControlInstance Message Inherits TextField
End Control
Control Label10 Inherits Label
ControlInstance Label10 Inherits Label
End Control
Control PostButton Inherits PushButton
ControlInstance PostButton Inherits PushButton
EventHandler Sub Action() SendMessage End EventHandler
End Control
Control Result Inherits TextField
ControlInstance Result Inherits TextField
End Control
Control Label11 Inherits Label
ControlInstance Label11 Inherits Label
End Control
Control DebugMessages Inherits TextField
ControlInstance DebugMessages Inherits TextField
End Control
Control HTMLViewer1 Inherits HTMLViewer
ControlInstance HTMLViewer1 Inherits HTMLViewer
End Control
Sub GetAccessToken() const URL = "https://api.twitter.com/oauth/access_token" dim c as new CURLSMBS call c.SetupOAuth(_ ConsumerKey.Text, _ ConsumerSecret.Text, _ RequestToken.text, _ RequestTokenSecret.text, _ "POST", _ URL, _ nil, _ nil, _ nil, _ "", _ // nonce "", _ // timestamp "", _ // HMAC Verifier.text) dim e as integer = c.Perform dim r as string = c.OutputData dim d as string = c.DebugMessages DebugMessages.Text = d if e <> 0 then Break end if dim SName, Token, TokenSecret as string dim values() as string = split(r, "&") for each entry as string in values dim p as integer = instr(entry, "=") if p > 0 then dim key as string = left(entry, p-1) dim val as string = mid(entry, p+1) Select case key case "oauth_token" Token = val case "oauth_token_secret" TokenSecret = val case "screen_name" SName = val end Select end if next if Token = "" and TokenSecret = "" then MsgBox "Failed to get a token!" else ScreenName.Text = SName AccessToken.Text = Token AccessTokenSecret.Text = TokenSecret end if End Sub
Sub GetRequestToken() const URL = "https://api.twitter.com/oauth/request_token" dim c as new CURLSMBS call c.SetupOAuth(_ ConsumerKey.Text, _ ConsumerSecret.Text, _ "", _ "", _ "POST", _ URL) dim e as integer = c.Perform dim r as string = c.OutputData dim d as string = c.DebugMessages DebugMessages.Text = d if e <> 0 then Break end if dim Token, TokenSecret as string dim values() as string = split(r, "&") for each entry as string in values dim p as integer = instr(entry, "=") if p > 0 then dim key as string = left(entry, p-1) dim val as string = mid(entry, p+1) Select case key case "oauth_token" Token = val case "oauth_token_secret" TokenSecret = val end Select end if next if Token = "" and TokenSecret = "" then MsgBox "Failed to get a token!" else RequestToken.Text = Token RequestTokenSecret.Text = TokenSecret end if End Sub
Sub SendMessage() const URL = "https://api.twitter.com/1.1/statuses/update.json" dim theMessage as string = "status=" + EncodeURLComponent(Message.Text) dim theData() as string = array(theMessage) dim c as new CURLSMBS call c.SetupOAuth(_ ConsumerKey.Text, _ ConsumerSecret.Text, _ AccessToken.text, _ AccessTokenSecret.text, _ "POST", _ URL, _ theData, _ nil, _ nil, _ "", _ // nonce "", _ // timestamp "", _ // HMAC "") dim e as integer = c.Perform dim r as string = c.OutputData dim d as string = c.DebugMessages DebugMessages.Text = d Result.Text = r if e <> 0 then Break end if End Sub
End Class
MenuBar MenuBar1
MenuItem FileMenu = "&Ablage"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Bearbeiten"
MenuItem EditUndo = "&Rückgängig"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "&Ausschneiden"
MenuItem EditCopy = "&Kopieren"
MenuItem EditPaste = "&Einfügen"
MenuItem EditClear = "#App.kEditClear"
MenuItem UntitledMenu0 = "-"
MenuItem EditSelectAll = "&Alles auswählen"
End MenuBar
End Project

The items on this page are in the following plugins: MBS CURL Plugin.


The biggest plugin in space...