Share Your Code

GGFacebook

Posted by Glitch Games, Posted on October 28, 2012

GitHub URL: 
https://github.com/GlitchGames/GGFacebook

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/

Require the code
local GGFacebook = require( "GGFacebook" )

Create your Facebook object passing in your apps id, optional listener and permissions
local facebook = GGFacebook:new( appID, listener, permissions )

Login
facebook:login()

Post to the users wall with a message and optional link
facebook:simplePost( "I just started playing Forever Lost by Glitch Games, it's really awesome!", "http://itunes.apple.com/us/app/forever-lost-episode-1-hd/id542364897?ls=1&mt=8" )

Post to the users wall with a table of options

1
2
3
4
5
6
7
8
local options = 
{
    message = "Check out this link!",
    link = "http://www.glitchgames.co.uk",
    name = "Glitch Games"
}
 
GGFacebook:post( options )

Upload an image from the documents directory with a message
facebook:uploadImage( "Check out this image!", "image.png", system.DocumentsDirectory )

Show a Facebook UI dialog
facebook:showDialog( action, params )

Logout
facebook:logout()

Destroy the Facebook object

1
2
facebook:destroy()
facebook = nil


Replies

LairdGames
User offline. Last seen 12 hours 46 min ago. Offline
Joined: 28 Oct 2011

LOVE THESE LIBRARIES! Thanks for sharing. It is too late for me to use this but I will definetly implement them in my next app.

Anyway to add GGTwitter and GGInapp ( in app purchase) in the future? That would be fantastic and would complete already superbe library!

THANKS!

Mo
@LairdGames

Glitch Games
User offline. Last seen 8 hours 28 min ago. Offline
Joined: 18 Jan 2012

Thanks! Glad to know at least one person ( other than us ) is using them :-)

Both GGTwitter and GGInApp are in my Coming Soon folder but I will bump them up the priority list now that they have been asked for specifically.

If you have any other ideas, either generic like Twitter or more game specific, please let me know so I can add them to the to-do list.

LairdGames
User offline. Last seen 12 hours 46 min ago. Offline
Joined: 28 Oct 2011

FANTASTIC news! Can't wait. Social and in-app are not obvious things in Corona and so your libraries are god sent.

I will definetly let you know if there is something else that would benefit a lot of people that you could add to the library.

Thanks again for sharing.

Mo

EDIT: maybe GGRating. I know there are some ways to do this but adding this could complete a nice library and allow people to use only set of libraries...yours!

Glitch Games
User offline. Last seen 8 hours 28 min ago. Offline
Joined: 18 Jan 2012

GGRating is actually on the to-do as we have had to write something a few times for our various apps and it gets tiresome :-)

paskuniak
User offline. Last seen 1 week 3 days ago. Offline
Joined: 21 May 2012

Please please please add support for posting using "me/scores" path... I've been trying to get facebook.request to work with it for weeks!

Glitch Games
User offline. Last seen 8 hours 28 min ago. Offline
Joined: 18 Jan 2012

@LairdGames - GGTwitter is now done and up, can be downloaded from here - http://developer.coronalabs.com/code/ggtwitter - :-)

@paskuniak - Haven't used the "me/scores" stuff before, I will look into it and see what I can do.

LairdGames
User offline. Last seen 12 hours 46 min ago. Offline
Joined: 28 Oct 2011

Cool! Wow that was fast!! Thank you. I will take a look but it seems easy enough. Adding the in-app will make these libraries complete!

THANKS!

Mo

Glitch Games
User offline. Last seen 8 hours 28 min ago. Offline
Joined: 18 Jan 2012

You're welcome! The InApp one is my next plan.

LairdGames
User offline. Last seen 12 hours 46 min ago. Offline
Joined: 28 Oct 2011

Cool. Can't wait!

Mo

Glitch Games
User offline. Last seen 8 hours 28 min ago. Offline
Joined: 18 Jan 2012

Took a side step on that one and just doing a basic GGRating first.

LairdGames
User offline. Last seen 12 hours 46 min ago. Offline
Joined: 28 Oct 2011

Still very cool anyway!

Mo

Glitch Games
User offline. Last seen 8 hours 28 min ago. Offline
Joined: 18 Jan 2012

GGRating is now up, see here and here.

rxmarccall
User offline. Last seen 2 weeks 5 days ago. Offline
Joined: 18 Jan 2011

@Glitch Games
Can you give me sample code of what you might use to make a call to login to facebook? I am using your library, and have my app all setup on facebook with my app ID and a android hash key, but when I try to login inside my app it says "App Name, is misconfigured for Facebook login. Press okay to go back to the application without it connecting to facebook."

Any thoughts about what I might be doing wrong? been stuck on this for a good while now.

Here is how I am trying to login with my code

1
2
3
local appID = "***************" (real app ID there)
facebook = GGFacebook:new( appID )
facebook:login()

Should I be putting my Android hash anywhere inside the GGFacebook:new( ) method call? am i missing anything? thanks!

Glitch Games
User offline. Last seen 8 hours 28 min ago. Offline
Joined: 18 Jan 2012

It sounds like you haven't set up your build.settings file for SSO, this link should help - http://www.coronalabs.com/blog/2012/01/04/implementing-facebook-single-sign-on/

chandler767
User offline. Last seen 9 weeks 2 days ago. Offline
Joined: 16 Nov 2011

Can you tell me what goes into permissions?

chandler767
User offline. Last seen 9 weeks 2 days ago. Offline
Joined: 16 Nov 2011

Actually can you just give me a block of code that I can just paste into my app to post a simple facebook message?

chandler767
User offline. Last seen 9 weeks 2 days ago. Offline
Joined: 16 Nov 2011

Ok,
I got it to login to facebook but it wont bring up the post dialog. Now what?

Glitch Games
User offline. Last seen 8 hours 28 min ago. Offline
Joined: 18 Jan 2012

It's not meant to bring up a dialog, the simplePost function just posts something you choose to the users wall, to bring up a dialog window you will want to look into the showDialog function.

rxmarccall
User offline. Last seen 2 weeks 5 days ago. Offline
Joined: 18 Jan 2011

@Glitch Games
Thanks for that link, I have looked over it. In the link it says that for Android you don't have to add anything into the build.settings file. I am trying to get it working for Android at the moment, do I need to include something for android in build.settings?

Glitch Games
User offline. Last seen 8 hours 28 min ago. Offline
Joined: 18 Jan 2012

I'm assuming you don't have to however I've never used it on Android so can't guarantee that.

rxmarccall
User offline. Last seen 2 weeks 5 days ago. Offline
Joined: 18 Jan 2011

Hmm ok, I got it setup and running on IOS, just not working on Android. If anyone around has got this working on Android, let me know what you did, thanks!

chandler767
User offline. Last seen 9 weeks 2 days ago. Offline
Joined: 16 Nov 2011

@Glitch Games How much would you want to do the following for me:

Write a sample app that combines both Facebook and Twitter. I want it so you tap a Facebook/Twitter button and it asks were you want to share. upon selection it logs them in and brings up a post dialog with a short message and a link.

I obviously cannot figure facebook integration out.

rxmarccall
User offline. Last seen 2 weeks 5 days ago. Offline
Joined: 18 Jan 2011

For anyone else having the same issue that I posted above, I got my issue resolved. I thought for sure I had the correct android hash key because I followed facebook's instructions on how to get it using the java SDK with a commandline call. Turns out it was false. I entered in "12345" in my facebook apps hash key. Then download the app "logcat", run your app and you will get the normal error that I had, and just click "okay" on the error that comes up. Then open "logcat", and you will find an error that has the facebook login error, and it will tell you the correct hash key there. Entered the one shown there and now my facebook login error is resolved, huzzah! hope this helps others.

Glitch Games
User offline. Last seen 8 hours 28 min ago. Offline
Joined: 18 Jan 2012

@ chandler767 - Please send an email to graham@glitchgames.co.uk and we can discuss exactly what you want.

@ rxmarccall - Glad you got it sorted and thanks for sharing the solution, will no doubt be useful for other people.

LairdGames
User offline. Last seen 12 hours 46 min ago. Offline
Joined: 28 Oct 2011

@GG

I am already using GGRating (works beautifuly!) but I am having some issue understanding how to use GGFacebook:

1- Does the simplePost just post the message (and optional image) to the user FB (wall I suppose) without any feedback to the user?

2- Is it possible to show the message that will be sent before it gets sent (so the user can approve or cancel)? I am assuming I need to use the

facebook:showDialog( action, params ) but even after looking at the link you provided, I am unsure how to format action and params? Any little example will be great!

3- I also assume that if that when I call facebook.login() the system should show me a window where I can enter my ID/password, correct? Then what happen if I have a Facebook app already installed or I do not have one installed?

I am very sorry for all these questions! I am very new to social media with Corona.

In any event, THANK YOU so much for all these wonderful libraries, they sure make life easier!

Mo.

ps: by the way, right now I am using this for my FB code:

1
 native.showWebPopup(_LEFT, _TOP, display.contentWidth, display.contentHeight - 50, "http://www.facebook.com/dialog/feed?display=touch&app_id="..app_id.."&redirect_uri="..redirectUri.."&link="..fbLink.."&picture="..fbPic.."&name="..fbName.."&description="..message ) 

Glitch Games
User offline. Last seen 8 hours 28 min ago. Offline
Joined: 18 Jan 2012

Happy to hear GGRating is helpful!

In answer to your questions:

1. Yes that is correct, it is meant for silent posts. Naturally you will not want to spam walls with this one :-)

2. Yea you will need to use showDialog, however I have wrapped up some calls to that to make it easier, you will want to use this:

facebook:makePost( "http://www.glitchgames.co.uk", "link to a picture", "name", "caption", "description" )

3. If you already have the app installed and logged in you will be taken to a screen asking you to authorise the app, if you don't have the app installed you will be taken to the facebook website to perform the same thing.

Happy to help, we're going to keep creating libs as and when we need them and release them as soon as they are tidied up.

LairdGames
User offline. Last seen 12 hours 46 min ago. Offline
Joined: 28 Oct 2011

THANKS!

I did not see:

facebook:makePost( "http://www.glitchgames.co.uk", "link to a picture", "name", "caption", "description" )

Sounds easy enough! Is the first link ( "http://www.glitchgames.co.uk") has to be my web site or could it be a direct link to the app iTunes URL?

I will try to implement both GGFacebook and GGTwitter before I release my first app and report here.

Thanks again.

Mo

Glitch Games
User offline. Last seen 8 hours 28 min ago. Offline
Joined: 18 Jan 2012

It can be a link to anything you want yea.

Hope it goes well, I can guarantee they both work on Android and iOS as we have an app coming soon that uses about half a dozen GG libs including those - http://www.glitchgames.co.uk/app/forever-lost-camera - it was made in a weekend :-)

LairdGames
User offline. Last seen 12 hours 46 min ago. Offline
Joined: 28 Oct 2011

Very cool of you to share these great libs. And thank you for getting back to me. I appreciate that very much since you are very busy I am sure. Can't wait for all the other goodies like GGStore and so on. These are already my favorite libs. I will implement Facebook and twitter and report here.

THANK YOU!

Mo

LairdGames
User offline. Last seen 12 hours 46 min ago. Offline
Joined: 28 Oct 2011

Hello again,

I am very sorry to bother again but I am having some issue with GGFacebook. here the error I am getting:

"...Nov 26 20:30:52 unknown UIKitApplication:com.lairdgames.SpaceCom[0x3f7c][1458] : ERROR: First argument to facebook.login() should be a string..."

I can see about the same message on the corona sim, as well as the console on Xcode when running on the device attached. I also cannot see anything happening on the device itself (even with the makePost ..see below)

Since I am sure it works for other people, it has to be something I am doing. here thew way i am calling the lib:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
-- in one of my module (director) I have
 
local GGFacebook = require( "GGFacebook" )
 
local facebook = GGFacebook:new(123456789012345678)
 
facebook:login()
 
-- and later when in button listener i have this (testing, i will change to a makePost later):
 
facebook:simplePost( "I just started playing Forever Lost by Glitch Games, it's really awesome!", "http://itunes.apple.com/us/app/forever-lost-episode-1-hd/id542364897?ls=1&mt=8" )
 
 
- I ALSO TRY THIS (nothing happens on the device)
 --facebook:makePost( "http://www.lairdgames.com", "SpaceCommand", "Space shooter", "Check it out!" )
                

Not sure if I need the facebook.lua from Coronalabs (I am assuming not since i am using GGFacebook)? I am also not sure where that message "First argument to facebook.login() should be a string." came from since I do not believe the sentence is from the GG lib? I am pretty sure I do not have the regular facebook required somewhere.

Any suggestions what I am doing wrong?

THANKS!

Mo

LairdGames
User offline. Last seen 12 hours 46 min ago. Offline
Joined: 28 Oct 2011

GOT IT!
local facebook = GGFacebook:new("123456789012345678") The app ID needed to be between ""

I have a misconfigured facebook but at least I can the dialog box..,wowowow!

Thanks again for a beautiful piece of code.

Mo

LairdGames
User offline. Last seen 12 hours 46 min ago. Offline
Joined: 28 Oct 2011

EDIT: My bundle ID was set wrong! Sorry for the false alarm. Now I am going to attack the GGTwitter!

I was able to post to my wall! Even so the app goes to my facebook app on my iphone and says "SpaceCommand" is misconfigured for Facebook login" press Ok to go back to the application without connecting it to Facebook"

Once I go back to the app I got another window (still in the game) that says "post to wall" and I can see my message and picture and if i press "share" button the message gets posted to the wall fine!

Do I need to worry about this? I do not really like when the system says that my app is misconfigured with Facebook:(

Thanks for any suggestions.

I love it when I making progress even if I am not there yet!

Mo

Glitch Games
User offline. Last seen 8 hours 28 min ago. Offline
Joined: 18 Jan 2012

Sorry I would have gotten back to you sooner but I was asleep :-)

Glad you solved the issues! The reason that you were able to post to the wall without a properly configured app is that the showDialog stuff doesn't require any permissions etc as the user has to actually hit the Post button. But in the end you have it all solved so that's great.

I find the Twitter stuff much simpler.

LairdGames
User offline. Last seen 12 hours 46 min ago. Offline
Joined: 28 Oct 2011

Hello,

Hey no problem at all. It was my fault, I made couple bad errors but now GGFacebook works like a charm!

Thank you!

Mo

Glitch Games
User offline. Last seen 8 hours 28 min ago. Offline
Joined: 18 Jan 2012

Awesome glad to hear it!

LairdGames
User offline. Last seen 12 hours 46 min ago. Offline
Joined: 28 Oct 2011

Thank you. It works perfectly. The only thing I noticed is that on the very first time, the app opens the Facebook app then after a second or two, comes back to the game then open the regular post to wall box but with no text nor the button cancel or share (just a white box with the close cross button top left) then the all box goes away. If I click on my custom FB button again (and any time after that) I can see the regular post to wall box but this time it is prefilled and both button cancel and share are shown. From that point I can post without any issue.

It will not bother me much but i am afraid users maybe confused by this behavior on the first launch of the post to wall window.

Any ideas why it would do that?

In any event, I am so happy I am almost done with implementing FB and TW thanks to your wonderful libs!

Mo

Glitch Games
User offline. Last seen 8 hours 28 min ago. Offline
Joined: 18 Jan 2012

Strange, I've not really used the dialog stuff but will look into it as soon as I can.

LairdGames
User offline. Last seen 12 hours 46 min ago. Offline
Joined: 28 Oct 2011

Hi again.

Anyway to have "like us" feature with the current GGFacebook? I am wondering if it can be done with the showDialog feature?

If it is planned feature that will great!

Thanks.

Mo

Glitch Games
User offline. Last seen 8 hours 28 min ago. Offline
Joined: 18 Jan 2012

I couldn't find a way to get it to work programatically but yea possibly through the showDialog stuff, I will take a look.

rxmarccall
User offline. Last seen 2 weeks 5 days ago. Offline
Joined: 18 Jan 2011

@GlitchGames or Anyone that might know.

I really like this library! What I am wanting to do, is if they click a button to post to facebook, I first check to see if they are logged into facebook, if they aren't after they finish, they then have to click the post to facebook button a second time, which confuses the user. Is there anyway in my code and using this library to have a function get called immediately after a user successfully logs in so it is a more seamless experience?

warrenwsav
User offline. Last seen 10 hours 9 min ago. Offline
Joined: 5 Oct 2012

Cam I use the MakePost with a local image on the phone? I saved a picture with my camera and want to post it on a page using the dialog.

Thanks!

Glitch Games
User offline. Last seen 8 hours 28 min ago. Offline
Joined: 18 Jan 2012

Yes you can, you can see this in action in our Forever Lost Camera app. However I don't think you can do this to any page other than your own due to the new changes in the Facebook API.

husam.sarris
User offline. Last seen 8 weeks 5 days ago. Offline
Joined: 13 Sep 2011

Thank you again GG guys!

I just have one issue,
When the Facebook button on my app is pressed, the user is able to log in.
The next step, is that my app posts a simple message using the Facebook:simple post("") which you indicated above.

The message simply doesn't make it to the timeline!

What problem do I have? Do I have to alter any settings on the facebook developers page?

Please help.

The twitter part works well now, scratch the comment I left under the GGTwitter code :)

Thanks.

Glitch Games
User offline. Last seen 8 hours 28 min ago. Offline
Joined: 18 Jan 2012

99% of the time the issues are caused by incorrect settings on the facebook app page however now that there have been some changes to the Facebook API I can't be 100% sure it isn't something to do with that. That being said though I don't think any of the changes will affect the simple post stuff so it could well be the app settings.

husam.sarris
User offline. Last seen 8 weeks 5 days ago. Offline
Joined: 13 Sep 2011

Thank you very much for replying on both posts.

I guess you are right.
The code looks clean, it is just a matter of app settings.

I've been working on it in the past few days, but still no luck.

Do you recommend any combination of settings?

I can't find much of space for "Play around" on the apps setting page.

Thank you for your help :)

Glitch Games
User offline. Last seen 8 hours 28 min ago. Offline
Joined: 18 Jan 2012

This tutorial helped me set it all up in the first place - http://www.coronalabs.com/blog/2012/01/04/implementing-facebook-single-sign-on/