Corona Facebook integration

Hi,

I am struggling and ganging my head on table for my App to communicate with facebook with no success. I have set up everything properly and trying to post a message with no success. I even tried the Facebook sample App but no success. 

Here are my build.settings

settings = { orientation = { default = "portrait", }, iphone = { plist= { UIStatusBarHidden=true, UIApplicationExitsOnSuspend = false, UIPrerenderedIcon = true, CFBundleDisplayName = "My App", UIAppFonts = { "League Gothic.ttf" }, FacebookAppID = "XXXXXXXXXXXX", CFBundleURLTypes = { { CFBundleURLSchemes = { "fbXXXXXXXXXXXX", } } } }, }, }

I am trying to post a message like this,

local callFacebook = function() local facebookListener = function( event ) if ( "session" == event.type ) then if ( "login" == event.phase ) then local theMessage = "I just took this quiz! I scored " .. finalscore .. " points!" facebook.request( "me/feed", "POST", theMessage) end end end facebook.login( "MyAppID", facebookListener, { "publish\_stream" } ) end local function callFB (event) if event.phase == "ended" then callFacebook() end end fbButton:addEventListener("touch", callFB)

I also did all the settings on facebook developer portal but only thing I am missing is Canvas URL. I am not sure what is it and is it really neccassary for App to work with Facebook. Please guide me where I am wrong or if this is Canvas URL causing the problem. I am stuck please help…!

Have you gone through this guide?

http://docs.coronalabs.com/guide/social/setupFacebook/index.html

Are you getting any errors in the console log?

Thanks Rob! I have gone through this guide many times and only thing I am missing is Canvas URL. This may be causing the problem. Can you please guide me what us canvas url and is it really necessary for app to communicate with facebook.

Thanks

Here is my facebook settings.  I don’t see this Canvas URL you are talking about.  Are you doing this on iOS or Android?

Are you getting any errors in your console log?  (Xcode’s organizer for iOS or “adb logcat” for android)?

facebook.jpg

Hello Rob,

When I try to post message on facebook, My App takes me to the facebook asking for permission to post. When I allow the app to post it returns back to MY App and noting is posted. Also it happens only first time after I have installed the app and after this when I tap the button to post nothing happes at all. I tried to use the sample facebook APp but same result. Here are the errors I get in  Xcode console

Apr 28 01:08:10 Robins-iPhone SpringBoard[16] <Warning>: Facebook[183]: Could not stat /private/var/mobile/Applications/6ADB5816-DC34-4126-9BB2-29909F91506C/Library/Caches/com.facebook.Facebook/com.apple.opengl/shaders.maps: No such file or directory

Apr 28 01:08:10 Robins-iPhone SpringBoard[16] <Warning>: Facebook[183]: Could not stat /private/var/mobile/Applications/6ADB5816-DC34-4126-9BB2-29909F91506C/Library/Caches/com.facebook.Facebook/com.apple.opengl/shaders.data: No such file or directory

Can you please guide me what is going wrong ? Will be much thankful for help

I think Canvas URL is only for an App on Facebook not a mobile App.

That is a very odd errror. Let me get the engineers to look at this for you.

Thanks Rob :slight_smile:

I will be waiting for response 

Have you gone through this guide?

http://docs.coronalabs.com/guide/social/setupFacebook/index.html

Are you getting any errors in the console log?

Thanks Rob! I have gone through this guide many times and only thing I am missing is Canvas URL. This may be causing the problem. Can you please guide me what us canvas url and is it really necessary for app to communicate with facebook.

Thanks

Here is my facebook settings.  I don’t see this Canvas URL you are talking about.  Are you doing this on iOS or Android?

Are you getting any errors in your console log?  (Xcode’s organizer for iOS or “adb logcat” for android)?

facebook.jpg

Hi Rob – I’m getting the same issue as rhmueed. I’m using apprequests, but same sort of problem. It appears as though the app has gone through the cycle of submitting the app request, but nothing appears to the facebook user.

Here are my console errors:

Apr 30 15:26:28 Stephens-iPhone backboardd[26] <Warning>: Facebook[3423]: Could not stat /private/var/mobile/Applications/088DEEEE-3BEB-48AB-B3F3-CCD49FE61B2C/tmp/etilqs_Dy5MKPYxfUPrWeI: No such file or directory
Apr 30 15:26:28 Stephens-iPhone backboardd[26] <Warning>: Facebook[3423]: Could not stat /private/var/mobile/Applications/088DEEEE-3BEB-48AB-B3F3-CCD49FE61B2C/tmp/etilqs_QjYvWQkXulgNZ0I: No such file or directory
Apr 30 15:26:28 Stephens-iPhone backboardd[26] <Warning>: Facebook[3423]: Could not stat /private/var/mobile/Applications/088DEEEE-3BEB-48AB-B3F3-CCD49FE61B2C/tmp/etilqs_Zg52FE56gxUppKZ: No such file or directory
Apr 30 15:26:28 Stephens-iPhone backboardd[26] <Warning>: Facebook[3423]: Could not stat /private/var/mobile/Applications/088DEEEE-3BEB-48AB-B3F3-CCD49FE61B2C/tmp/etilqs_hFjyENMrlmo6Hmb: No such file or directory

Yeah same issue here, app goes through the motions to post, but nothing gets posted.  Please test this.

I am getting the same issue, where it takes me to Facebook to post, but does not post.   This is using build 2012.894.  When trying to post with build 2012.1076, it doesn’t even go to Facebook.

Here is the Facebook controller code, whose externally facing functions (at the bottom) are called by any function needing Facebook functionality.  The Facebook configuration on FB’s side configuration is exactly the same as Rob Miracle’s above.

[lua]

module(…, package.seeall)

 

facebookControllerInstance = nil

 

function facebook_controller:getFacebookControllerInstance()

    if facebookControllerInstance then

        return facebookControllerInstance

    end

 

    local facebook = require “facebook”

    require “facebook_meta”

 

    facebookControllerInstance = {}

    local JSON = require(“JSON”)

 

    local appId = facebook_meta[“appID”]

    local apiKey = facebook_meta[“apiKey”]

    local appLink

    local deviceOS = system.getInfo(“platformName”)

 

    if deviceOS == “iPhone OS” then

        appLink = facebook_meta[“iOS”]

    else

        appLink = facebook_meta[“Android”]

    end

 

    local fbCommand

    local POST_MSG = 1

    local GET_USER_INFO = 2

    local postLevelAch = true

    local postMainAch = false

    local postAmmoAch = false

    local achInfo = {}

    local wallData, userData

 

    local function getMessageInfo()

        if postLevelAch then

            wallData.caption = userData.name … facebook_meta[“level_part1”] … achInfo.score … facebook_meta[“level_part2”] … achInfo.level … facebook_meta[“level_part3”]

            wallData.picture = facebook_meta[“achievement_image”]

        elseif postMainAch then

            wallData.caption = userData.name … facebook_meta[“achievement_part1”] … achInfo.giftName … facebook_meta[“achievement_part2”]

            wallData.picture = facebook_meta[“achievement_image”]

        elseif postAmmoAch then

            wallData.caption = userData.name … " won an " … achInfo.giftName … facebook_meta[“level_part3”]

            wallData.picture = facebook_meta[“achievement_image”]

        else

            wallData.caption = userData.name … facebook_meta[“chapter_part1”] … achInfo.chapter … facebook_meta[“chapter_part2”]

            wallData.picture = facebook_meta[“achievement_image”]

        end

    end

 

    local function fbListener( event )

        if event.type == “session” then

            if event.phase == “login” then

                if fbCommand == POST_MSG then

                    getMessageInfo()

                    facebook.request(“me/feed”, “POST”, wallData)

                    native.showAlert(“Achievement Shared!”, “Your achievement has been successfully posted to Facebook!”, {“OK”})

                elseif fbCommand == GET_USER_INFO then

                    facebook.request(“me”)

                end

            end

        elseif event.type == “request” then

            if event.isError then return end

            local response = event.response

 

            if fbCommand == GET_USER_INFO then

                userData = JSON:decode(response)

                getMessageInfo()

                fbCommand = POST_MSG

                facebook.login(appId, fbListener, {“publish_stream”})

            end

        end

    end

 

    local function callWallPost()

        wallData = {

            name = facebook_meta[“app_name”],

            link = appLink,

            actions = JSON:encode({name = facebook_meta[“app_name”], link = appLink})

        }

 

        if userData then

            fbCommand = POST_MSG

        else

            fbCommand = GET_USER_INFO

        end

 

        facebook.login(appId, fbListener, {“publish_stream”})

    end

 

    facebookControllerInstance.postLevelAchievement = function(self, level, score)

        achInfo.level = level

        achInfo.score = score

        callWallPost()

    end

 

    facebookControllerInstance.postMainAchievement = function(self, giftName, giftImage)

        postLevelAch = false

        postMainAch = true

        achInfo.giftName = giftName

        achInfo.giftImage = giftImage

        callWallPost()

    end

 

    facebookControllerInstance.postAmmoAchievement = function(self)

        postLevelAch = false

        postAmmoAch = true

        achInfo.giftName = “an ammo pack”

        achInfo.giftImage = “ui_ammo_icon”

        callWallPost()

    end

 

 

    facebookControllerInstance.postChapterAchievement = function(self, chapter)

        postLevelAch = false

        achInfo.chapter = chapter

        callWallPost()

    end

 

    return facebookControllerInstance

end

[/lua]

And here is build.settings

[lua]

settings =

{

    androidPermissions =

    {

       “android.permission.VIBRATE”,

       “android.permission.INTERNET”,

       “com.android.vending.BILLING”,

       “android.permission.READ_PHONE_STATE”,

       “android.permission.ACCESS_NETWORK_STATE”,

       “android.permission.ACCESS_WIFI_STATE”

 

    },

    orientation =

    {

        default = “landscapeRight”,

        supported =

        {

            “landscapeRight”,

        },

    },

    iphone =

    {

        plist=

        {

            UIApplicationExitsOnSuspend = false,

            UIStatusBarHidden=true,

            UIPrerenderedIcon = true,

            FacebookAppID = “XXXXXXXXXXXX” [ID stripped from this forum for security]

            CFBundleIdentifier = “something.something.something” [ID stripped from this forum for security]

            CFBundleDisplayName = “App Name” [ID stripped from this forum for security]

            CFBundleURLTypes =

            {

                {

                    CFBundleURLSchemes =

                    {

                        “fbXXXXXXXXXXXXX”, [ID stripped from this forum for security]

                        CFBundleIconFile = “Icon.png”,

                    }

                }

            },

            CFBundleIconFiles = {

                “Icon.png” ,

                “Icon@2x.png” ,

                “Icon-72.png” ,

            },

            UIAppFonts =

            {

                [fonts used — stripped from this forum post]

 

            },

        },

        components = {}

    }

}

[/lua]

That’s quite a bit of complex code to look at.  But I have to ask a very dumb question.  Are you expecting to use our built in JSON library or are you providing your own?   The require(“JSON”) is looking for an upper case JSON entry which in the sim doesn’t matter, but it could thrown an error on a device since we are using lower case “json”.

Also why are you logging in multiple times?  You login, get a ‘me’ object and then in handling the return of the “me” object, you login again?  You should login once, and then do facebook.requests()'s to fetch further data, unless I missed a logout in there somewhere.

Rob good tips.  I have removed double login, and switched the json library from the custom library (yes we were using a custom library) that was being used to the one corona has built in.  

Sorry for just throwing a bunch of messy spaghetti code into your part of the internet, I know it’s a little tough to read.  

The core part that’s making me bang my head against the wall is this part: 

[lua]facebook.login(appId, fbListener, {“publish_actions”})[/lua]

Last night I wrote a little bit of dummy code (using the AppID of my existing Facebook app) to test facebook login inside my main.lua main() function which is show below.

[lua]

    local facebook = require “facebook”

    local json = require “json”

    local function fbListener(event)

        local wallData

        wallData = {

            name = “my game name”,

            link = “[my app link]”,

            actions = json.encode({name = “my game name”, link = “[my app link]”})

        }

        if ( “session” == event.type ) then

            – upon successful login, request list of friends of the signed in user

            if ( “login” == event.phase ) then

                facebook.request( “me/friends”, “POST”, wallData )

            end

        end

    end

    facebook.login("[my existing Facebook app ID]", fbListener, {“publish_actions”})

[/lua]

With corona 2012.894 it fetches permissions, but then hangs with a blank login window when it gets to Facebook (looks like the below)

With 2013.1076 it doesn’t even try to login at all.

Any ideas on why this might be happening or what i could do to debug?

Hello Rob,

When I try to post message on facebook, My App takes me to the facebook asking for permission to post. When I allow the app to post it returns back to MY App and noting is posted. Also it happens only first time after I have installed the app and after this when I tap the button to post nothing happes at all. I tried to use the sample facebook APp but same result. Here are the errors I get in  Xcode console

Apr 28 01:08:10 Robins-iPhone SpringBoard[16] <Warning>: Facebook[183]: Could not stat /private/var/mobile/Applications/6ADB5816-DC34-4126-9BB2-29909F91506C/Library/Caches/com.facebook.Facebook/com.apple.opengl/shaders.maps: No such file or directory

Apr 28 01:08:10 Robins-iPhone SpringBoard[16] <Warning>: Facebook[183]: Could not stat /private/var/mobile/Applications/6ADB5816-DC34-4126-9BB2-29909F91506C/Library/Caches/com.facebook.Facebook/com.apple.opengl/shaders.data: No such file or directory

Can you please guide me what is going wrong ? Will be much thankful for help

I think Canvas URL is only for an App on Facebook not a mobile App.

That is a very odd errror. Let me get the engineers to look at this for you.

Thanks Rob :slight_smile:

I will be waiting for response