3

I am trying to share my app created in corona sdk free version in facebook. But no working example found on internet. It seems there is a change in facebook api or policy. Does any one have created app in corona sdk with facebook integration recently ? Can any one provide me referece to the way we can integrate the facebook.

I found another question sharing my app through facebook in corona Sdk but the link provided in answer is down. It would be greate= help.

Is there any update in facebook API ? as I am getting response null every time. can any one provide working example reference created recently ?

I tried the example provided by krs in following answer but it is not working for me. https://developer.coronalabs.com/content/facebook when I click on any of the feature like post Msg it goes to facebook page and after some processing it directly comes to the home page again nothing gets done. In log I ma getting response null.

following is screenshot of error.

enter image description here

any help will be great help to me.

EDIT

I had tried a lot but the same issue is there. I think facebook app configuration problem is there. Can anyone provide detailed step by step information to configure an app and generate build in corona ? I am giving another 100 point bounty for this.

Community
  • 1
  • 1
Hemant Metalia
  • 29,730
  • 18
  • 72
  • 91

2 Answers2

5

I hope this helps make a lua file and copy this code name it whatever you want

local facebook = require "facebook"
local json = require "json"

local _M = {}

local appId = "" -- put your app id string here

local message = ""
local access_token = ""
local fbCommand = ""

local LOGOUT = 1
local SHOW_DIALOG = 2
local POST_MSG = 3
local POST_PHOTO = 4
local GET_USER_INFO = 5
local GET_PLATFORM_INFO = 6

function showPopup(popupTitle,popupMessage)
    native.showAlert( popupTitle, popupMessage, {"OK"} )
end


function listener( event )
    if ( "session" == event.type ) then

        if ( "login" ~= event.phase ) then
            showPopup("Facebook share score failed!", "Please try again")
            return
        end

        print(access_token)
        access_token = event.token


        if fbCommand == GET_USER_INFO then
            facebook.request("me")
        elseif fbCommand == POST_MSG then

            facebook.request("me/feed", "POST"  , {message = message} )
        end
    elseif ( "request" == event.type ) then
        local response = event.response

        print("Response: ",response)

        if ( not event.isError ) then
            if fbCommand == GET_USER_INFO then
                response = json.decode( event.response )
            elseif fbCommand == POST_MSG then
                showPopup("Facebook share score", "You've successfully shared your score!")
            end
        else
            showPopup("Facebook share score failed!", "Please try again")
        end
    end
end

function _M:postToWall(msg)
    message = msg
    fbCommand = POST_MSG
    facebook.login( appId, listener, {"publish_stream"} )
end

function _M:shareGame()
    message = "Juggler http://google.com/"
    fbCommand = POST_MSG
    facebook.login( appId, listener, {"publish_stream"} )
end

return _M

and when you want to share on use this function

  local function FacebookShare(event)

        if event.phase == "began" then
            local FBManager
            local message

            FBManager = require( "Facebook" )
            message = "" -- your message
            FBManager:postToWall(message)
        end
    end

if user is not login it will call login facebook. this works for me hope it solve your problem

DevfaR
  • 1,586
  • 1
  • 9
  • 19
  • Thanks for your answer can you please also send me reference do we need to follow for configuring app id with facebook ? Is hashkey is must ? – Hemant Metalia May 24 '13 at 05:57
  • https://developers.facebook.com/ this is the link for configuring appID and about the hashkey you need to use the corona debug keystore to get the hashkey if you using a trial in corona – DevfaR May 24 '13 at 06:13
  • It gives me same error every time Invalid android_key parameter. The key JGn9F2vDQ_w6hexLxdefCUpxYIA does not match any allowed key. Configure your app key hashes at http://developers.facebook.com/apps/377851258992260 I have updated my hashkey but still the same error is shown. – Hemant Metalia May 26 '13 at 09:33
  • i think you're using the wrong hashkey. how do you get your key hash did you use openssl this might help http://stackoverflow.com/questions/4388992/key-hash-for-android-facebook-app. and by the way if your using windows and your using x64 bit OS openssl64 must be use – DevfaR May 27 '13 at 01:17
  • I think it is only issue of configuring app with facebook as code is proper. We have tried only appid without any platform specification it worked. but in my other android where facebook app is old(not updated) this is not working Is it the case of facebook api change ? – Hemant Metalia May 27 '13 at 04:50
  • ohh i haven't test it yet on device running 2.2 below if that's the case for older version of facebook or android i think it will be better to authorize the application in web view since web is always updated – DevfaR May 27 '13 at 06:10
  • it worked on a day before but currently this is also not working.. can you please help me ? I have a urgent work can you please contact me on my email address as this is very important for me as i am going to release my game soon but i didnt get this thing done. – Hemant Metalia May 29 '13 at 15:01
  • okay what is your email address i'll send to you a working example – DevfaR May 30 '13 at 01:00
  • I have sent you a mail can you please check it and revert me back ? It would be a great help – Hemant Metalia May 30 '13 at 06:01
4

There is facebook sample app from ansca labs. See that from the link below:

https://developer.coronalabs.com/content/facebook

And there is an integration in the app Ghosts-vs.-Monsters

https://github.com/ansca/Ghosts-vs.-Monsters

Keep coding......... :)

Krishna Raj Salim
  • 7,331
  • 5
  • 34
  • 66
  • will it require appkey right ? as I have gone through some blogs they used appkey retrieved from facebook. and I do not have apppkey as I dont know the appkey of the person who have installed my app. – Hemant Metalia May 16 '13 at 14:13
  • 1
    I think this may help you to solve this issue: http://docs.coronalabs.com/guide/social/setupFacebook/index.html – Krishna Raj Salim May 16 '13 at 18:06
  • And the portal setup is described here: http://docs.coronalabs.com/guide/social/setupFacebook/index.html#register-app – Krishna Raj Salim May 16 '13 at 18:10
  • I tried to do this but it is not working for me. as it is not working in simulator and i am not able to see log in device. can you please let me know as this is old api is there any change from facebook api ? or it is working fine currently ? – Hemant Metalia May 20 '13 at 06:22
  • Is there any update in facebook API ? as I am getting response null every time. can any one provide working example reference created recently ? – Hemant Metalia May 21 '13 at 06:12