Posting savescreen to FB

102 views Asked by At

I need help to solve this problem: I want to post on FB a save screen from my app (I got save screen by using display.save function). Everything works fine on Android while on my iPad it crashes! Please find the function code below:

local function postonFB( event)
    display.save( tab3fields, { filename="ticket.jpg", baseDir=system.DocumentsDirectory, isFullResolution=true, backgroundColor={0, 0, 0, 0} } )

    local fbAppID = "4531113981XXXXX"  
    local function fbListener( event )
        if event.phase == "login" then
            local attachment = {
                message="I am a champion!",
                source= {baseDir=system.DocumentsDirectory, filename="ticket.jpg", type="image"}
            }

            facebook.request("me/photos", "POST", attachment)
            native.showAlert("Facebook", "Submitted!")
        end
    end

    -- photo uploading requires the "publish_actions" permission
    facebook.login( fbAppID, fbListener, { "publish_actions" } )
end

Please help, I am getting crazy to understand what's wrong! Thanks a lot. Ubaldo

1

There are 1 answers

13
mmkevind On

here is my facebook sharing code:

baseDir = system.DocumentsDirectory
display.save( group , "screenshot.png", system.DocumentsDirectory )

local facebook = require "facebook"
local fbAppID = "898209XXXXXXXXX" 

function onLoginSuccess()
    attachment = {
    message = "i got ".. score .. " blablabla",
    source = { baseDir=system.DocumentsDirectory, filename="screenshot.png", type="image" }
    }
    facebook.request( "me/photos", "POST", attachment )
end

function fbListener( event )
    if event.isError then
        native.showAlert( "ERROR", event.response, { "OK" } )
    else
        if event.type == "session" and event.phase == "login" then
            onLoginSuccess()
        elseif event.type == "request" then
            print("upload done")
        end
    end
end
facebook.login( fbAppID, fbListener, { "publish_stream", "publish_actions" } )

ps do you have this in you build.settings?

plugins =
{
    ["facebook"] =
    {
        publisherId = "com.coronalabs"
    },

},