Platforms to show: All Mac Windows Linux Cross-Platform
Required plugins for this example: MBS Main Plugin, MBS MacBase Plugin, MBS Mac64bit Plugin
Last modified Fri, 3rd Mar 2022.
You find this example project in your MBS Xojo Plugin download as a Xojo project file within the examples folder: /Mac64bit/Post To Facebook
Download this example: Post To Facebook.zip
Project "Post To Facebook.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
End Class
Class FacebookWindow Inherits Window
Control RequestAccessButton Inherits PushButton
ControlInstance RequestAccessButton Inherits PushButton
EventHandler Sub Action()
me.Enabled = false
accountType = accountStore.accountTypeWithAccountTypeIdentifier(ACAccountTypeMBS.ACAccountTypeIdentifierFacebook)
dim options as new Dictionary
options.Value(ACAccountTypeMBS.ACLinkedInAppIdKey) = "xxx" // "<YOUR FACEBOOK APP ID KEY HERE>"
options.Value(ACAccountTypeMBS.ACFacebookPermissionsKey) = array("publish_stream") // publish_stream", "publish_actions")
options.Value(ACAccountTypeMBS.ACFacebookAudienceKey) = ACAccountTypeMBS.ACFacebookAudienceFriends
accountStore.requestAccessToAccountsWithType(accountType, options)
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 Facebook account?"
Return
end if
dim FacebookAccount as ACAccountMBS = Accounts(UBound(Accounts))
dim dic as new Dictionary
dic.Value("status") = MessageField.Text
dic.Value("access_token") = FacebookAccount.credential.oauthToken
const requestURL = "https://graph.facebook.com/me/feed"
dim postRequest as new mySLRequestMBS( SLRequestMBS.SLServiceTypeFacebook, SLRequestMBS.SLRequestMethodPOST, requestURL, dic)
postRequest.account = FacebookAccount
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)
FacebookWindow.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("Facebook 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:
Download this example: Post To Facebook.zip
The items on this page are in the following plugins: MBS Mac64bit Plugin.