Facebook posting on Android

Can you post more code?  Where are you doing the facebook.login() call?  What is your build.settings look like?

Rob

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.

I think you’re running into the same issue another person is having.  The facebook.* calls are asynchronous which means that the next statements execute right away and don’t wait on the facebook.* calls to complete.  Adding the 3 second delay is your attempt to solve that.  The only problem is that facebook.login() may take longer than 3 seconds to happen.  If it has to prompt the user for permission and such, that could be well longer than 3 seconds.

I would put the facebook.request() call inside the fblistener function inside of the “session” check:

local function facebookListener( event ) &nbsp; &nbsp; print( "event.name", event.name ) &nbsp;--"fbconnect" &nbsp; &nbsp; print( "event.type:", event.type ) --type is either "session", "request", or "dialog" &nbsp; &nbsp; print( "isError: " .. tostring( event.isError ) ) &nbsp; &nbsp; print( "didComplete: " .. tostring( event.didComplete ) ) &nbsp; &nbsp; print(event.response) &nbsp; &nbsp; --"session" events cover various login/logout events &nbsp; &nbsp; --"request" events handle calls to various Graph API calls &nbsp; &nbsp; --"dialog" events are standard popup boxes that can be displayed &nbsp; &nbsp; if ( "session" == event.type ) then &nbsp; &nbsp; &nbsp; &nbsp; --options are: "login", "loginFailed", "loginCancelled", or "logout" &nbsp; &nbsp; &nbsp; &nbsp; if ( "login" == event.phase ) then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; local access\_token = event.token &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; --code for tasks following a successful login &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; facebook.request( "me/feed", "POST", { message="Hello Facebook" } )&nbsp;&nbsp; \<----- HERE &nbsp; &nbsp; &nbsp; &nbsp; end &nbsp;

You might also want to consider a flag that determines if you’re logged in or not.  If you’re logged in, then don’t call facebook.login() a 2nd time but call facebook.request() instead.

Rob

With your suggestion, moving the request to the listener, still not working.  I get the same android screen that says Facebook: my game would like to access your public profile and friends list, hit ok, then nothing happens.

logcat shows:

I/Corona  ( 1580): event.name   fbconnect

I/Corona  ( 1580): event.type:  session

I/Corona  ( 1580): isError: false

I/Corona  ( 1580): didComplete: nil

any other thoughts?

Interestingly there are like three threads reporting a similar issue, which would lead me to suspect there is a problem  I’ve spent my time today constructing a very basic Facebook app.  I’ve verified that it runs correctly on both iOS 7 (iPhone 5) and on Android 4.4 (Google Nexus 7).

build.settings

settings = { &nbsp;&nbsp;&nbsp; orientation = &nbsp;&nbsp;&nbsp; { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; default = "portrait", &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; supported = { "portrait" } &nbsp;&nbsp;&nbsp; }, &nbsp;&nbsp;&nbsp; android = &nbsp;&nbsp;&nbsp; { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; usesPermissions = &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "android.permission.INTERNET", &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }, &nbsp;&nbsp;&nbsp; }, &nbsp;&nbsp;&nbsp; plugins = &nbsp;&nbsp;&nbsp; { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -- key is the name passed to Lua's 'require()' This section is only required for builds \> 2014.2165 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ["facebook"] = &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -- required &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; publisherId = "com.coronalabs", &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; supportedPlatforms = { iphone = true, ["iphone-sim"] = true }, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }, &nbsp;&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bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "Icon-76.png", &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "Icon-76@2x.png", &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "Icon-Small.png", &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "Icon-Small@2x.png", &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "Icon-Small-40.png", &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "Icon-Small-40@2x.png", &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "Icon-Small-50.png", &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "Icon-Small-50@2x.png", &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; UIApplicationExitsOnSuspend = false,&nbsp;&nbsp;&nbsp; -- must be false for single sign-on to work &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FacebookAppID = "XXXX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p;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;&nbsp;&nbsp; } }

main.lua

io.output():setvbuf('no') local widget = require( "widget" ) local json = require( "json" ) local facebook = require( "facebook" ) local facebookAppID = "XXXXXXXXXXXXXXX" local FB\_Command = nil function print\_r ( t ) &nbsp;&nbsp;&nbsp; local print\_r\_cache={} &nbsp;&nbsp;&nbsp; local function sub\_print\_r(t,indent) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (print\_r\_cache[tostring(t)]) then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print(indent.."\*"..tostring(t)) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print\_r\_cache[tostring(t)]=true &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (type(t)=="table") then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for pos,val in pairs(t) do &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (type(val)=="table") then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print(indent.."["..pos.."] =\> "..tostring(t).." {") &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sub\_print\_r(val,indent..string.rep(" ",string.len(pos)+8)) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print(indent..string.rep(" ",string.len(pos)+6).."}") &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; elseif (type(val)=="string") then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print(indent.."["..pos..'] =\> "'..val..'"') &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print(indent.."["..pos.."] =\> "..tostring(val)) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print(indent..tostring(t)) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end &nbsp;&nbsp;&nbsp; end &nbsp;&nbsp;&nbsp; if (type(t)=="table") then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print(tostring(t).." {") &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sub\_print\_r(t,"&nbsp; ") &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print("}") &nbsp;&nbsp;&nbsp; else &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sub\_print\_r(t,"&nbsp; ") &nbsp;&nbsp;&nbsp; end &nbsp;&nbsp;&nbsp; print() end local function facebookListener( event ) &nbsp;&nbsp; &nbsp;print\_r( event ) &nbsp;&nbsp;&nbsp; print( "event.name", event.name )&nbsp; --"fbconnect" &nbsp;&nbsp;&nbsp; print( "event.type:", event.type ) --type is either "session", "request", or "dialog" &nbsp;&nbsp;&nbsp; print( "isError: " .. tostring( event.isError ) ) &nbsp;&nbsp;&nbsp; print( "didComplete: " .. tostring( event.didComplete ) ) &nbsp;&nbsp;&nbsp; if ( "session" == event.type ) then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; --options are: "login", "loginFailed", "loginCancelled", or "logout" &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ( "login" == event.phase ) then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; local access\_token = event.token &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; --code for tasks following a successful login &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print( 'Token: ' .. access\_token ) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if FB\_Command then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;facebook.request( FB\_Command ) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end &nbsp;&nbsp;&nbsp; elseif ( "request" == event.type ) then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print("facebook request") &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ( not event.isError ) then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; local data = json.decode( event.response ) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print( "data: ", data ) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print( "event.response: ", event.response ) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;print( "event.isError: " .. event.isError ) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end &nbsp;&nbsp;&nbsp; end end local function doFacebook( event ) &nbsp;&nbsp; &nbsp;if event.phase == "ended" then &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;FB\_Command = "me" &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;facebook.login( facebookAppID, facebookListener, {"publish\_actions", "email" }) &nbsp;&nbsp; &nbsp;end end local fbButton = widget.newButton({ &nbsp;&nbsp; &nbsp;label = "Facebook", &nbsp;&nbsp; &nbsp;onEvent = doFacebook &nbsp;&nbsp; &nbsp;}) fbButton.x = display.contentCenterX fbButton.y = display.contentCenterY facebook.login( facebookAppID, facebookListener )

This should be minimalist Facebook app.  It does a 2 pass login, the first time requesting basic permissions, then when you hit the button, it asks for additional permissions.  Once your app runs and these have been granted you won’t be prompted again.   The things printed to the console log are the things I would expect to see.

You can use this or use the Sample app in the SampleCode/Network/Facebook folder to verify your settings.

I will be up front and was very frustrated because it just wasn’t working for me.  Then I used the build.settings from the sample app replacing my build.settings.  It suddenly started working.  This is another thing you can try.  Replace your build.settings with the one from the sample app.

Rob

I will give this a try, my test android device is a galaxy s2 version 4.1.2

Any chance the simple “social” plug-in to post to Facebook will work on Android? I appreciate the code above and would probably implement it, but for me, it was dead easy to implement my ‘share to email/text/Twitter/Facebook feature’ in my game using the native.showPopup method without having to even set up an app ID on Facebook.

There is an outstanding bug with Android and Facebook that prevents Android Sharing Intent’s from posting to Facebook.  So the only way to get Android apps to post to Facebook is to use the Facebook SDK.  Since this Intent doesn’t work, we filter it out.

Used your code Rob, and the build.settings from the scrumptious app, now I am getting 

V/Corona (11269): \> Class.forName: CoronaProvider.ads.admob.LuaLoader V/Corona (11269): \< Class.forName: CoronaProvider.ads.admob.LuaLoader V/Corona (11269): Loading via reflection: CoronaProvider.ads.admob.LuaLoader I/Corona (11269): BUILD NUMBER IS: 2189 I/Corona (11269): USING GRAPHICS OUTLINES: true I/Corona (11269): ADMOB AD - Event: The ad loaded successfully I/Corona (11269): table: 0x5f5830a8 { I/Corona (11269): [type] =\> "session" I/Corona (11269): [name] =\> "fbconnect" I/Corona (11269): [phase] =\> "loginCancelled" I/Corona (11269): [isError] =\> false I/Corona (11269): [response] =\> "" I/Corona (11269): }

In one of the other threads they found that not having the facebook native app but having the facebook messanger app caused this.  Take the Corona filter off of the adb logcat (i.e. run adb logcat with no parameters) and see if you’re getting any errors from other intents.

Rob

Hi everyone, seem i got this issue happen while try to login with facebook via android device, it seem login function did not work,

but all my facebook App configure seem got everything in android platform, package name, class, and key hash,

but i cant event login with that, or do i miss anything with Facebook App?

it always return below value

03-18 16:57:03.897: I/Corona(24463):   type    session

03-18 16:57:03.897: I/Corona(24463):   name    fbconnect

03-18 16:57:03.897: I/Corona(24463):   phase    loginCancelled

03-18 16:57:03.897: I/Corona(24463):   isError    false

03-18 16:57:03.897: I/Corona(24463):   response    

Run your adb logcat without any parameters.  The way most people learn to run adb logcat only shows messages from the Corona app, not other intents like Facebook and look for other errors. 

Another poster found the Facebook Messenger app was at fault.  Another found that his hash key really wasn’t right afterall.   All of these were found by running adb logcat and looking for non-Corona messages.

Rob

@Rob does it require our App on Android Store or not to make this work?

You will want it in Google Play so Facebook can link to it to let people download it.  But its not required for testing.

Rob

Thank you Rob, one more thing that i am not clear with Facebook api as when I post a link to Facebook I need the link could be open an App if App installed and go to download if not. How can we do that?

Sorry Rob, I have had to be offline a few days. I dont have a facebook messenger app installed. I was still getting api errors when I would output my logcat to a text file.(I mean thats what the file was reporting). So I read in another forum where the problem was with facebook applications and to delete the app and make a new one.  So this is where it gets interesting, I did that on Monday, and for the past 2 days after that I am now getting Hash key errors, but have the same hash key o_0. Im almost at my wits end here.

cap2.jpg

cap3.jpg

Facebook knows if your app is installed or not.  I would presume they manage to try and load your app for you if you tap on it from the Facebook mobile app.  This is one of the uses for providing the URL scheme on iOS.  On Android, it uses the App’s reverse domain name.  If the person is on the browser, then it will use information you put in your portal to direct you to the right app store.

However any links you provide will likely only be links to web based resources.

@david.newman, that message is quite clear.  Your hash key isn’t right.  Some people are able to take the string from the console log and just use it.  Facebook is telling you what they want.  Have you tried that?

yeah Rob, hence the screenshots, they are the same

= \