Post to facebook walls from your application
Monkey Forums/Monkey Programming/Post to facebook walls from your application
| ||
Edit: I made some changes to the code, the popup problem in my post below is fixed in this version and a popup should be generated regardless of sitting in an iframe I also added the ability to change the caption. This is a copy of the code I wrote in my alphaburn game. I am a beginner so criticize at will hopefully encourage some improvements because this is Ugly Anyway you can import it into your applications and then use the 2 methods to post to peoples facebook walls. It requires you to register your app on facebook in order to work how I intended. It requires a small initial setup in OnCreate and also the fabulous Diddy module put this in your main class Class Game extends DiddyApp Field Facebook:FacebookObject Method OnCreate() Facebook = New FacebookObject Facebook.SetupApp([FBAppID],[AppName],[LogoImageURL],[AppURL]) End To post a message use (using fields from code above) Facebook.WallPost([Caption],[Message],[PopupT/F]) This is the full module code Import diddy Class FacebookObject Field varAppID:String = "" Field varAppRedir:String = "" Field varAppLogo:String = "" Field varAppName:String = "" Field varAppURL:String = "" Method WallPost(Caption:String,Message:String,Popup:Bool) If varAppID <> "" Then Local lvarDisplayType:String If Popup = True Then lvarDisplayType="popup" Else lvarDisplayType = "page" LaunchBrowser("https://www.facebook.com/dialog/feed?app_id="+varAppID+"&link="+varAppURL+"&picture="+varAppLogo+"&name="+ varAppName + "&caption="+Caption+"&description="+Message+"&redirect_uri="+ varAppURL+"&display="+lvarDisplayType,Popup) Else Error("FACEBOOK MODULE ERROR: Cannot send message, the fb application settings are incorrect") EndIf End Method Method SetUpApp:int(AppID:String,AppName:String,AppLogoURL:String,AppURL:String) 'Sanatise inputs and display errors 'Sanitise AppID If AppID.Length > 30 Then Error("FACEBOOK MODULE WARNING: AppID is incorrect") Return 0 Else varAppID = AppID EndIf 'Sanitise AppName If AppName.Length > 60 Then Error("FACEBOOK MODULE WARNING: App name is too long") Return 0 Else varAppName = AppName EndIf if AppLogoURL.Contains(".gif") = True or AppLogoURL.Contains(".png") = True or AppLogoURL.Contains(".jpg") = True or AppLogoURL.Contains(".jpeg") Then varAppLogo=AppLogoURL Else Error("FACEBOOK MODULE WARNING: The app logo must be a link to gif/jpg/png stored on the internet, all in lower case, it cannot be an image embedded in the app") Return 0 EndIf if AppURL.Contains("http://") = True Then varAppURL = AppURL Else Error("FACEBOOK MODULE WARNING: The App url needs to be a web address, it also needs to be registered to your app on the facebook developers site") Return 0 EndIf Return 1 End Method End |
| ||
not tested this yet but that is very cool and something I will use, facebook has become such a big part of the gaming world these days, I think the total number of users it has is insane. perfect place to pimp your game by allowing your players to facebook it. |
| ||
This is cool since it is based on Diddy's LaunchBrowser only. But what will happen if the device is not connected to the internet? You gave me a really great idea for a feature I need to add to my app. Thanks. |
| ||
I would imagine you will recieve the default browser "cannot find page" response. Ive only used this on flash / html5 so a connection was expected.. Edit: The problem below is fixed in the updated code above ** Another point is if the game is embedded in an Iframe using popups might not work, so unless its the end of your game and the current state does not matter it probably wants saving before calling the wallpost method... This is doable with SaveState and LoadState for simple games. This is only an issue for the HTML5/Flash Targets just incase they get redirected off the current page and only if your calling halfway through a game. |