Using GGFacebook, facebook.login() does NOTHING

Hello everyone. I have reached the stage of my app where I am adding in the final details. Currently I have been trying to implement Facebook (and Twitter). I have decided to use GGFacebook to make everything easier for me. Well after reading dozens of tutorials I was able to successfully implement facebook… or so I thought. When I call GGFacebook’s login function, the function activates but facebook.login() doesn’t do anything. I’ve check the logs on my Android phone and facebook throws no errors. I was wondering if it was something that I have done wrong.

Here is my main share function. Please note that this is in a storyboard scene (if that matters).

[spoiler]

local GGFacebook = require( "GGFacebook" ) local facebook = GGFacebook:new( xxxxxxxxxxxxxx,fListen,"publish\_actions") local facebookButtton = display.newImage( "assets/menu/shareF.png",320,400) group:insert(facebookButtton) --This is my storyboard group local function facebookShare(e) if e.phase == "ended" then facebook:login() facebook:simplePost( "Wow! I got") end end facebookButtton:addEventListener( "touch", facebookShare ) 

[/spoiler]

Everything seems to work fine here. Here is the GGFacebook login function i’m trying to call. When I do call it, it successfully prints “Logged in”. So I know for a fact that this function is being called successfully.

[spoiler]

function GGFacebook:login() print("Logged in") facebook.login( self.appID, self.internalListener, self.permissions ) end 

[/spoiler]

So I currently thing that is has something to do with my build.settings. Here they are.

[spoiler]

settings = { orientation = { default = "portrait", supported = { "portrait", } }, iphone = { plist = { UIAppFonts = { "JandaManateeSolid.ttf", }, -- iOS app URL schemes: CFBundleIconFiles = { "Icon.png", "Icon@2x.png", "Icon-Small-40.png", "Icon-Small-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" }, CFBundleDisplayName = "GGTwitter", UIStatusBarHidden = true, UIPrerenderedIcon = true, UIApplicationExitsOnSuspend = false, FacebookAppID = xxxxxxxxxxxxx, CFBundleURLTypes = { { CFBundleURLSchemes = { "fbxxxxxxxxxxxxx", -- example scheme for facebook } } } } }, androidPermissions = { "android.permission.INTERNET", "android.permission.WRITE\_EXTERNAL\_STORAGE", }, plugins = { ["facebook"] = { publisherId = "com.coronalabs", supportedPlatforms = { iphone=true, ["iphone-sim"]=true }, }, }, }  

[/spoiler]

And finally, here is the GGFacebook class that I am using.

[spoiler]

-- Project: GGFacebook -- -- Date: October 27, 2012 -- -- Version: 0.1 -- -- File name: GGFacebook.lua -- -- Author: Graham Ranson of Glitch Games - www.glitchgames.co.uk -- -- Update History: -- -- 0.1 - Initial release -- -- Comments: -- -- GGFacebook makes connecting and posting messages or images to Facebook very easy. -- More functions will be added in the future. -- -- You must have a Facebook app set up with SSO enabled, see this tutorial - -- http://www.coronalabs.com/blog/2012/01/04/implementing-facebook-single-sign-on/ -- -- Copyright (C) 2012 Graham Ranson, Glitch Games Ltd. -- -- Permission is hereby granted, free of charge, to any person obtaining a copy of this -- software and associated documentation files (the "Software"), to deal in the Software -- without restriction, including without limitation the rights to use, copy, modify, merge, -- publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons -- to whom the Software is furnished to do so, subject to the following conditions: -- -- The above copyright notice and this permission notice shall be included in all copies or -- substantial portions of the Software. -- -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, -- INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR -- PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE -- FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -- OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -- DEALINGS IN THE SOFTWARE. -- ---------------------------------------------------------------------------------------------------- local GGFacebook = {} local GGFacebook\_mt = { \_\_index = GGFacebook } local facebook = require( "facebook" ) --- Initiates a new GGFacebook object. -- @param appID The id of your app. -- @param listener Function to be called on Facebook events. Optional, and GGFacebook has an internal one. If you have one and don't want the GGFacebook one to take action just return true in yours. -- @param permissions A table of strings corresponding to Facebook permissions. -- @return The new object. function GGFacebook:new( appID, listener, permissions ) print("Creates facebook object") local self = {} setmetatable( self, GGFacebook\_mt ) self.appID = appID self.listener = listener self.permissions = permissions self.accessToken = nil self.internalListener = function( event ) self.accessToken = event.token if self.listener then if self.listener( event ) then return true end end if event.type == "session" then if event.phase == "login" then self.loggedIn = true end end end return self end --- Login to Facebook. function GGFacebook:login() print("Logs into facebook") facebook.login( self.appID, self.internalListener, self.permissions ) end --- Logout from Facebook. function GGFacebook:logout() facebook.logout() end --- Posts a status update to the users feed. -- @param message The message to post. -- @param link A link to include with the post, useful for promoting your app. Optional. function GGFacebook:simplePost( message, link ) self:post{ message = message or "", link = link } end --- Posts a status update to the users feed. -- @param options A table containing the paramaters of the post. See this page for help: https://developers.facebook.com/docs/reference/api/post/ function GGFacebook:post( options ) facebook.request( "me/feed", "POST", options ) end --- Uploads an image. -- @param message The message to include with the photo. Optional. -- @param filename The filename of the image to upload. -- @param baseDir The base directory of the image. Optional, defaults to system.DocumentsDirectory. function GGFacebook:uploadImage( message, filename, baseDir ) local attachment = { message = message or "", source = { baseDir = baseDir or system.DocumentsDirectory, filename = filename, type = "image" } } facebook.request( "me/photos", "POST", attachment ) end --- Shows a Facebook dialog page for allowing the user to do stuff. See this page for help: http://developers.facebook.com/docs/reference/dialogs/ -- @param action The dialog you want to show. -- @param params Table of paramaters passed to the Facebook API. function GGFacebook:showDialog( action, params ) facebook.showDialog( action, params ) end --- Send a request to a user. -- @param message The message to include with the request. -- @param to Either a single ID of a Facebook user to send to or a table or IDs. Optional, leave out to just bring up the multi-user select screen. -- @param title Title for the dialog, optional and max of 50 characters. function GGFacebook:sendRequest( message, to, title ) local params = {} params.message = message or "" params.title = title if to then if type( to ) == "table" then params.to = "" for i = 1, #to, 1 do params.to = params.to .. to[i] if i \< #to then params.to = params.to .. "," end end else params.to = to end end self:showDialog( "apprequests", params ) end --- Send a link to a user. -- @param to The user id or username of the person to send it to. -- @param link The link to send. -- @param picture The url to a picture to use for the link. Optional, by default one will be pulled from the link. -- @param name The name of the link. Optional, by default one will be pulled from the link. -- @param description The description of the link. Optional, by default one will be pulled from the link. function GGFacebook:sendLink( to, link, picture, name, description, to ) local params = {} params.to = to params.link = link params.picture = picture params.name = name params.description = description self:showDialog( "send", params ) end --- Make a post on a wall. -- @param link The link to post. -- @param picture The url to a picture to use for the link. Optional, by default one will be pulled from the link. -- @param name The name of the link. Optional, by default one will be pulled from the link. -- @param caption The caption of the link. Optional, by default one will be pulled from the link. -- @param description The description of the link. Optional, by default one will be pulled from the link. -- @param to The user id or username of the person whose wall wall this will be posted on. Optional, default is the current user. function GGFacebook:makePost( link, picture, name, caption, description, to ) local params = {} params.to = to params.link = link params.picture = picture params.name = name params.caption = caption params.description = description self:showDialog( "feed", params ) end --- Checks if the user is logged in, only works if you're listener function doesn't block the internal one. -- @return True if logged in, false otherwise. function GGFacebook:isLoggedIn() return self.loggedIn end --- Destroys the Facebook object. function GGFacebook:destroy() self.appID = appID self.listener = listener self.permissions = permissions end return GGFacebook&nbsp;

[/spoiler]

Before anyone asks, yes I set up my app on facebook’s dev site. I have filled out the package name, class name, and key hash. I have also made sure to enable Single Sign On, Deep Linking, and Native App.

If anyone can help me solve this issue I have been working on for a while I would be EXTREMELY grateful. And if a solution is found, I hope I can use that for GGTwitter as well. 

Thank you very much.

-Summit Tech

We really can’t provide support for Graham’s libraries.  You should contact Glitch Games for help.

But in general, for Android, build.settings do not come into play other than making sure you have your internet permission.  Secondly, Facebook now requires that requests for “publish_actions” comes in the form of a second login at the time you need the permissions and not at app start up.  Also, they now require apps to be approved that want “published_actions” or any extended permission.   Finally, our facebook.login(), which Graham is using is an asynchronous operation.  That is it returns immediately and the next lines in your program will execute before the login process finishes.  At the point you call facebook:simplePost() you are not logged in yet.   Normally this would go into your listener function after you have confirmed your permissions and facebook returns control back to your app.

In fact, Facebook is so async, your app will actually be suspended while Facebook is handling the login process and you get an applicationResume event when you come back.  You would not code anything here, you need to wait for the callback function on facebook.login() to get called.

Rob

Thank you Rob for your response. I will definitely try to contact Glitch Games for some assistance. I decided to try using the normal Facebook api. Let’s just say it was definitely more successful. I was prompted to allow app access to my public profile and friends list. Success!

Here is what the listener printed 

RESPONSE: OK

event.name fbconnect

event.type: session

isError: false

didComplete: nil

Everything seems fine. The only thing that worries me is didComplete = nil.

I then tried to use this.

facebook.request( "me/feed", "POST", { message="App test" } )

However that did not work.  

event.name fbconnect

event.type: request

isError: true

didComplete: false

facebook request

I think this is a result of not signing in twice, something that confuses me. If I understand you correctly, I have 2 facebook logins

The first should look like this

facebook.login( fbAppID, listener)

and the second should look like this

facebook.login( fbAppID, listener, "published\_actions" )

And then after logging in for a second time, I can successfully post?

My current code only has the latter of the two logins.

Thanks

Have you gotten your app approved by Facebook yet?  If you don’t want to ask for approval yet, you can set your app up in the Facebook developer portal as a test app.

Rob

Hey Rob, I just applied for approval. Thanks for letting me know! Currently I am trying to use the test app, but the same thing happens the event isError = true. Seems like it should work, but it doesn’t.

What errors are in your device’s console log?  Make sure to just do:

adb logcat

and not include any of the filtering options.  There should be more information available.  Also make sure to print out the event.response value as well.

If .isError is true, there is a reason and between the console log and the event.response it should show you the issue.

Rob

Using the unfiltered logcat I get no additional information. None whatsoever. Didcomplete still equals nil when I try to login. And the event.response is “(#200) The user hasn’t authorized the application to perform this action”. I modified my code a bit so that it logs in twice and then posts.

There are four possible reasons.

  1. Your keyhash is not correct.  This would prevent Facebook from handling the login handshake correctly.  There should be a warning in your console log telling you exactly what keyhash it’s expecting (though you have to tweak a couple of things in it).

2.  You’re login process is not asking for “publish_actions” in a second call to facebook.login().

3.  You  have not gotten Facebook to approve you having “publish_actions” yet.

4.  When Facebook requested the user to grant “publish_actions”, they said “No”.  Facebook remembers this.  See this web page for more information on this issue:

https://support.evvnt.com/hc/en-us/articles/202009463-Why-can-t-I-post-to-Facebook-

Rob

Thanks for the help Rob! I have FINALLY got it to work! Thanks again!

-Summit Tech

We really can’t provide support for Graham’s libraries.  You should contact Glitch Games for help.

But in general, for Android, build.settings do not come into play other than making sure you have your internet permission.  Secondly, Facebook now requires that requests for “publish_actions” comes in the form of a second login at the time you need the permissions and not at app start up.  Also, they now require apps to be approved that want “published_actions” or any extended permission.   Finally, our facebook.login(), which Graham is using is an asynchronous operation.  That is it returns immediately and the next lines in your program will execute before the login process finishes.  At the point you call facebook:simplePost() you are not logged in yet.   Normally this would go into your listener function after you have confirmed your permissions and facebook returns control back to your app.

In fact, Facebook is so async, your app will actually be suspended while Facebook is handling the login process and you get an applicationResume event when you come back.  You would not code anything here, you need to wait for the callback function on facebook.login() to get called.

Rob

Thank you Rob for your response. I will definitely try to contact Glitch Games for some assistance. I decided to try using the normal Facebook api. Let’s just say it was definitely more successful. I was prompted to allow app access to my public profile and friends list. Success!

Here is what the listener printed 

RESPONSE: OK

event.name fbconnect

event.type: session

isError: false

didComplete: nil

Everything seems fine. The only thing that worries me is didComplete = nil.

I then tried to use this.

facebook.request( "me/feed", "POST", { message="App test" } )

However that did not work.  

event.name fbconnect

event.type: request

isError: true

didComplete: false

facebook request

I think this is a result of not signing in twice, something that confuses me. If I understand you correctly, I have 2 facebook logins

The first should look like this

facebook.login( fbAppID, listener)

and the second should look like this

facebook.login( fbAppID, listener, "published\_actions" )

And then after logging in for a second time, I can successfully post?

My current code only has the latter of the two logins.

Thanks

Have you gotten your app approved by Facebook yet?  If you don’t want to ask for approval yet, you can set your app up in the Facebook developer portal as a test app.

Rob

Hey Rob, I just applied for approval. Thanks for letting me know! Currently I am trying to use the test app, but the same thing happens the event isError = true. Seems like it should work, but it doesn’t.

What errors are in your device’s console log?  Make sure to just do:

adb logcat

and not include any of the filtering options.  There should be more information available.  Also make sure to print out the event.response value as well.

If .isError is true, there is a reason and between the console log and the event.response it should show you the issue.

Rob

Using the unfiltered logcat I get no additional information. None whatsoever. Didcomplete still equals nil when I try to login. And the event.response is “(#200) The user hasn’t authorized the application to perform this action”. I modified my code a bit so that it logs in twice and then posts.

There are four possible reasons.

  1. Your keyhash is not correct.  This would prevent Facebook from handling the login handshake correctly.  There should be a warning in your console log telling you exactly what keyhash it’s expecting (though you have to tweak a couple of things in it).

2.  You’re login process is not asking for “publish_actions” in a second call to facebook.login().

3.  You  have not gotten Facebook to approve you having “publish_actions” yet.

4.  When Facebook requested the user to grant “publish_actions”, they said “No”.  Facebook remembers this.  See this web page for more information on this issue:

https://support.evvnt.com/hc/en-us/articles/202009463-Why-can-t-I-post-to-Facebook-

Rob

Thanks for the help Rob! I have FINALLY got it to work! Thanks again!

-Summit Tech

Hi,

I’m having problems to make GGFacebook work on my update. It used to work fine in the last submission ~10 months ago. 

I see that we now hove to login twice?

Summit Tech, Can you show the code version that worked for you?

Hi,

I’m having problems to make GGFacebook work on my update. It used to work fine in the last submission ~10 months ago. 

I see that we now hove to login twice?

Summit Tech, Can you show the code version that worked for you?