Ok so this will be a bit lengthy, I will keep it as short as possible and post snippets of my code.
build.settings –
settings ={ plugins = { -- key is the name passed to Lua's 'require()' ["CoronaProvider.ads.admob"] = { -- required publisherId = "com.coronalabs", }, --key is the name passed to Lua's 'require()' ["CoronaProvider.native.popup.social"] = { --required publisherId = "com.coronalabs", }, }, orientation = { default = "portrait", --landscapeRight supported = { "portrait", } }, iphone = { plist = { UIStatusBarHidden = true, UIAppFonts = { "kenpixel\_mini\_square.ttf" }, CFBundleIconFiles = { "Icon.png", "Icon@2x.png", "Icon-40.png", "Icon-40@2x.png", "Icon-60.png", "Icon-60@2x.png", "Icon-72.png", "Icon-72@2x.png", "Icon-76.png", "Icon-76@2x.png", "Icon-Small-50.png", "Icon-Small-50@2x.png", "Icon-Small.png", "Icon-Small@2x.png", "Icon-Small-40.png", "Icon-Small-40@2x.png" } } }, android = { versionCode = "12", usesPermissions = { "android.permission.INTERNET", "android.permission.ACCESS\_NETWORK\_STATE", "android.permission.READ\_PHONE\_STATE", }, }, }
So in this game there is a main.lua, menu.lua, game.lua files. main.lua is self explanatory which immediately calls menu.lua to start the game. It also stores globals for sound and admob.
menu.lua just holds the intro animation and start button, once tap start we go t game.lua where everything else is handled.
So this brings me to my game.lua file, where I will not post the entire thing (its long…really long) but give you the basic set up of how I am trying to post. I guess I should also mention I am using story boards.
local storyboard = require( "storyboard" )local scene = storyboard.newScene() local physics = require ("physics") --Require physics local facebook = require( "facebook" ) local json = require( "json" ) local function facebookListener( event ) print( "event.name", event.name ) --"fbconnect" print( "event.type:", event.type ) --type is either "session", "request", or "dialog" print( "isError: " .. tostring( event.isError ) ) print( "didComplete: " .. tostring( event.didComplete ) ) print(event.response) --"session" events cover various login/logout events --"request" events handle calls to various Graph API calls --"dialog" events are standard popup boxes that can be displayed if ( "session" == event.type ) then --options are: "login", "loginFailed", "loginCancelled", or "logout" if ( "login" == event.phase ) then local access\_token = event.token --code for tasks following a successful login end elseif ( "request" == event.type ) then print("facebook request") if ( not event.isError ) then local response = json.decode( event.response ) print(event.response) --process response data here end elseif ( "dialog" == event.type ) then print( "dialog", event.response ) --handle dialog results here print(event.response) end print(event.response) end
…stuff
local fbButton local fbPost fbButton = display.newImageRect(gameGroup, "assets/social\_f.png", 200, 50) fbButton.x = \_W / 2 fbButton.y = \_H / 2 + 100 fbButton.alpha = 0 fbButton:addEventListener("touch", fbPost) -- Transition in the game over screen local transitionDelay = 1000 local transitionTime = 300 transition.to(gameOverImage, {alpha=1, y=\_H/2-170, time=transitionTime, delay=transitionDelay}) transition.to(gameOverScoreboard, {alpha=1, time=transitionTime, delay=transitionDelay}) transition.to(tryAgainButton, {alpha=1, time=transitionTime, delay=transitionDelay}) transition.to(fbButton, {alpha=1, time=transitionTime, delay=transitionDelay}) timer.performWithDelay(transitionDelay + transitionTime, displayScores) -- Stop creating new walls timer.cancel(wallTimer) -- Update the highscore if score \> highscore then highscoreFile = io.open(system.pathForFile("highscore", system.DocumentsDirectory), "w") highscore = score highscoreFile:write("" .. score) highscoreFile:close() highscoreFile = nil end end elseif event.phase == "ended" and not isGameOver then if event.other.isSensor then score = score + 1 if score \> highscore then scoreLabel.text = "" .. score .. "!" else scoreLabel.text = "" .. score end playSound("score") end end end fbPost = function(event) local fbAppID = "xxxxxxxxxxxxxxxx" facebook.login( fbAppID, facebookListener, { "publish\_actions" } ) timer.performWithDelay(3000, facebook.request( "me/feed", "POST", { message="Hello Facebook" } ) ) -- end
This is essentially the order in which I have my code in also. Just to note I recently added the time delay to Facebook post request because I thought maybe I wasn’t giving enough time between login and posting. Seems not to be the case.
*EDIT: I should also note that I was trying the “publish_stream” I can put “publish_actions” in the login also, and I get nothing. Same results.