Platforms to show: All Mac Windows Linux Cross-Platform

/Mac64bit/Post To Twitter


Required plugins for this example: MBS Mac64bit Plugin, MBS MacBase Plugin, MBS Main Plugin

You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Mac64bit/Post To Twitter

This example is the version from Fri, 3rd Mar 2022.

Project "Post To Twitter.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
End Class
Class TwitterWindow Inherits Window
Control RequestAccessButton Inherits PushButton
ControlInstance RequestAccessButton Inherits PushButton
EventHandler Sub Action() me.Enabled = false accountType = accountStore.accountTypeWithAccountTypeIdentifier(ACAccountTypeMBS.ACAccountTypeIdentifierTwitter) accountStore.requestAccessToAccountsWithType(accountType, nil) End EventHandler
End Control
Control iMessage Inherits Label
ControlInstance iMessage Inherits Label
End Control
Control MessageField Inherits TextField
ControlInstance MessageField Inherits TextField
End Control
Control PostButton Inherits PushButton
ControlInstance PostButton Inherits PushButton
EventHandler Sub Action() dim Accounts() as ACAccountMBS = accountStore.accountsWithAccountType(accountType) if Accounts.Ubound = -1 then MsgBox "No twitter account?" Return end if dim twitterAccount as ACAccountMBS = Accounts(UBound(Accounts)) dim dic as new Dictionary dic.Value("status") = MessageField.Text const requestURL = "https://api.twitter.com/1.1/statuses/update.json" dim postRequest as new mySLRequestMBS( SLRequestMBS.SLServiceTypeTwitter, SLRequestMBS.SLRequestMethodPOST, requestURL, dic) postRequest.account = twitterAccount postRequest.performRequest End EventHandler
End Control
EventHandler Sub Open() #if TargetMacOS and Target64Bit then accountStore = new myACAccountStoreMBS #else RequestAccessButton.Enabled = False MsgBox "This example is for Xojo 2015r3 with 64-bit app." #endif End EventHandler
Sub AccessGranted(granted as Boolean, Error as NSErrorMBS) PostButton.Enabled = granted RequestAccessButton.Enabled = not granted if error <> nil then MsgBox Error.LocalizedDescription end if End Sub
Note "Plugins"
to run this example, you need this plugins MBS Mac64bit Plugin MBS Main Plugin MBS MacCloud Plugin MBS MacBase Plugin MBS MacCocoa Plugin MBS MacControls Plugin MBS MacCG Plugin MBS MacCF Plugin and Xojo 2015r3
Property accountStore As myACAccountStoreMBS
Property accountType As ACAccountTypeMBS
End Class
MenuBar MainMenuBar
MenuItem FileMenu = "&File"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem EditSeparator1 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "#App.kEditClear"
MenuItem EditSeparator2 = "-"
MenuItem EditSelectAll = "Select &All"
End MenuBar
Class myACAccountStoreMBS Inherits ACAccountStoreMBS
EventHandler Sub requestAccessCompleted(granted as boolean, error as NSErrorMBS, accountType as ACAccountTypeMBS, tag as variant) TwitterWindow.AccessGranted granted, error End EventHandler
End Class
Class mySLRequestMBS Inherits SLRequestMBS
EventHandler Sub performRequestCompleted(responseData as memoryblock, urlResponse as NSURLResponseMBS, error as NSErrorMBS, tag as variant) dim n as integer = urlResponse.statusCode if n = 200 then MsgBox "OK" else MsgBox "Failed with HTTP Status: "+str(n)+" "+urlResponse.localizedStringForStatusCode(n) dim f as FolderItem = SpecialFolder.Desktop.Child("twitter response.txt") dim b as BinaryStream = BinaryStream.Create(f, true) b.Write responseData b.Close end if End EventHandler
End Class
End Project

See also:

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


The biggest plugin in space...