Forum QuickConnect Posting to facebook wall (or stream)

Discussion and help relating to PlayerIO's QuickConnect feature, including Facebook Connect and Kongregate Connect.

Posting to facebook wall (or stream)

Postby actionsprite » July 1st, 2010, 6:36 am

Hi!

I've used quick connect to successfully log in to facebook via Flash, and my next step is to publish game acheivements to the player's wall (or to their stream - whichever the correct terminology is). How would I acheive this?

It would be really handy if there were some helper functions within Player.IO to facilitate something like this as I think it'd probably be a fairly common request. The Adobe-Facebook API is really hard to get your head around - its a shame it's so poorly documented.

JMC

P.S. are you going to make a Quick Connect forum room?
actionsprite
 
Posts: 21
Joined: June 26th, 2010, 1:01 am

Re: Posting to facebook wall (or stream)

Postby Benjaminsen » July 1st, 2010, 9:03 am

Hi actionsprite

You are in luck. Just yesterday I created this example of how to Auth towards the facebook API and request data.
In the example it requests your friendslist, but the principle is the same for posting to walls.

I do however agree with you that the Adobe facebook API is hard to get started with. Guess we should write a few tutorials to help people getting started.

/Chris
Benjaminsen
.IO
 
Posts: 1444
Joined: January 12th, 2010, 11:54 am
Location: Denmark

Re: Posting to facebook wall (or stream)

Postby actionsprite » July 2nd, 2010, 6:41 am

Hi Chris,
Thanks for the example, as you know I used it to establish a connection to facebook and it works wonderfully.

I have managed to post a link to the users wall, and update their status, but have spent the last two days hitting my head against the wall trying to work out how to publish a news item (in this case it would be a custom game achievement with an image and custom text) to the stream/feeed/wall. It doesn't seem as straight forward as grabbing the friend list.

Any chance of putting up a quick example showing how to do this?

Cheers,
JMC
actionsprite
 
Posts: 21
Joined: June 26th, 2010, 1:01 am

Re: Posting to facebook wall (or stream)

Postby Benjaminsen » July 2nd, 2010, 11:49 am

Hey JMC

I can see how post to wall can be none trivial. This mostly comes down to all the media types you need to wrap your head around and the permission system not being trivial to use either.

Specifically for permissions you need the users approval to post on the wall before it's even possible. You need to either ask the user for this permission when they "install" your application or spawn a popup when you want to post to the wall. The former is trivial, as you just have to put "publish_stream" into the permissions array when you call facebookConnectPopup or facebookConnect.

Asking for permissions later is pretty easy if you use a canvas page on facebook. But with facebookConnectPopup it’s again none trivial. In fact I had to use a few, yet to be documented, features to make the example below work.
Anyway to make a long story short, here are updated files:

Example:
http://chrisbenjaminsen.com/stuff/facebookconnect.swf

Source:
http://chrisbenjaminsen.com/stuff/facebookconnect.zip
Benjaminsen
.IO
 
Posts: 1444
Joined: January 12th, 2010, 11:54 am
Location: Denmark

Re: Posting to facebook wall (or stream)

Postby actionsprite » July 5th, 2010, 5:34 am

Hi Chris, that works perfectly!

I had been going off the Flash/Facebook docs and wasn't aware of "PublishPost" at all - crazy that it isn't documented.

Does the user need to log in through the game every time they play, or is there some cookie or other system that will allow an 'always logged in' type approach? I've been looking at the Mochi system and they appear to keep the user details for next time you go to the site.

JMC
actionsprite
 
Posts: 21
Joined: June 26th, 2010, 1:01 am

Re: Posting to facebook wall (or stream)

Postby Benjaminsen » July 5th, 2010, 9:02 am

If you request the access property offline_access from the user, the session key returned by the API will takes days to expire instead of minutes.

See: http://wiki.developers.facebook.com/ind ... ermissions & http://stackoverflow.com/questions/6170 ... h-facebook
Benjaminsen
.IO
 
Posts: 1444
Joined: January 12th, 2010, 11:54 am
Location: Denmark

Re: Posting to facebook wall (or stream)

Postby actionsprite » July 5th, 2010, 9:10 am

Thanks Chris, when the user next loads up the swf file, is there a way to check for an active facebook session rather than making them use the javascript popup to log in/validate each time they load up the game.

I seem to have had success by storing the session key and session secret on the user's machine in a Shared Object, and then starting a new WebSession with those values:

Code: Select all
facebook = new Facebook()
var mySession:WebSession  = new WebSession(<api_key>,<stored_session_secret>, <stored_Session_key>)
facebook.startSession(mySession)
//
var call:FacebookCall = facebook.post( new GetLoggedInUser())
call.addEventListener(FacebookEvent.COMPLETE,handleUser)


This seems to work fine as I am able to post a status update directly afterwards, but I'm not sure if this is too simplistic an approach. I will also have to cater for if the session has elapsed.

[EDIT] Added in GetLoggedInUser call to test if the session key and secrets are still valid, if not valid I'd then go through the pop up log in process I guess [/EDIT]

JMC
actionsprite
 
Posts: 21
Joined: June 26th, 2010, 1:01 am

Re: Posting to facebook wall (or stream)

Postby Benjaminsen » July 5th, 2010, 10:57 am

Hah, your to fast for me, you did it exactly as it should be done. Saving peoples session secret in a Shared Object, and validating it automatically.
Benjaminsen
.IO
 
Posts: 1444
Joined: January 12th, 2010, 11:54 am
Location: Denmark

Re: Posting to facebook wall (or stream)

Postby actionsprite » July 6th, 2010, 1:25 am

I zipped up a new flashdevelop project with my ammends to allow for storing a session cookie.

It stores the session secret and the session key in a shared object.

I don't store the uid as I am using the other session details to check for logged in status. If successful this process returns the current user id so it seemed to work well to go through that process and validate the session at the same time.

facebook_connect_ammends.zip
Facebook Connect with session restart
(242.16 KiB) Downloaded 1504 times


Hope it's useful :)
JMC
actionsprite
 
Posts: 21
Joined: June 26th, 2010, 1:01 am


Return to QuickConnect



cron