As recently facebook stopped supporting the feedstory publishing method to publish news on users wall and application developers from now on can't create feed templates. Facebook released a new methods to do so which are:
FB.Connect.streamPublish
stream.publish
Facebook.streamPublish
I figured out those new methods when I was building a new facebook application yesterday to predict who will win the soccer match between Egypt and Algeria tonight. It took me sometime to succeed in publishing the story on the wall, so I will share with you my experience and how I solved it out in Coldfusion.
As I build my applications using the work of Andrew Duckett who created the Facebook Rest Client Component, I will start from FacebookFBMLCLient.cfc file which contains the methods that communicates with facebook APIs.
As I have used one of the three methods above which sounded the best as I guess, this example will be based on stream.publish method.
The first step is to add the following method to the FacebookFBMLCLient.cfc file:
<cffunction name="publishStream" access="public" output="false" returntype="any" hint="Publish on Wall">
<cfargument name="session_key" type="string" required="true" hint="the session id of the logged in user">
<cfargument name="to_ids" type="string" required="true" hint="ids of all the friends user has chosen">
<cfargument name="message" type="string" required="true" hint="message">
<cfargument name="attachment" type="Any" required="true" hint="JSON Object">
<cfargument name="action_links" type="Any" required="true" hint="JSON Object">
<!--- local vars --->
<cfset var params = StructNew() />
<!--- the api call --->
<cfset params["session_key"] = arguments.session_key />
<!--- <cfset params["uids"] = arguments.to_ids />--->
<cfset params["message"] = arguments.message />
<cfset params["attachment"] = arguments.attachment />
<cfset params["action_links"] = arguments.action_links />
<!--- Invoke stream.publish API --->
<cfset sendNoteVar = xmlToStructParam('facebook.stream.Publish',params) />
<cfreturn sendNoteVar />
</cffunction>
The second step is that you need permission from the users of the application to grant the method permission to publish on their walls, this can be done in many ways see this link, in my application I ask the permission from users when they submit the form, which I believe is the best way. So if you are using a form in your application you may get the permission to publish on users wall by By including the promptpermission attribute in the form as below:
<form name="Form" promptpermission="publish_stream" action="Action.cfm" method="post">
The third step is to call the publish stream method:
<cfset attachment = '{"properties":{"Votes":{"text":"Members Voted: (#eg# Votes for EGYPT)(#al# Votes for ALGERIA) (No Winner #equ#)","href":"#faceBookPath#/#appName#","rating":"rate"}},"media": [{"type":"image","src":"http://www.abusalah.info/fbapps/fbapp3/imgs/Algeria.jpg","href":"http://apps.facebook.com/algeria-egypt/"}]}'>
<cfset action_links = '[{"text":"Make Your Prediction","href":"#faceBookPath#/#appName#"}]'>
<cfset #FBMLClient.publishStream(session.fb_session_key,session.fb_uid,answer1,attachment,action_links)#>
The attachment and action_links must be in JSON format, any simple format mistake will prevent the attachment or the action_links from being published, so you should be careful.
Please note that I didn't use all options that can be published using Stream.Publish method, you may add more options to your code see the list of media and other options here.
I believe thats all what you need to publish to wall using the new facebook api's, if you need any help or have any question please add a comment to the article.
FB.Connect.streamPublish
stream.publish
Facebook.streamPublish
I figured out those new methods when I was building a new facebook application yesterday to predict who will win the soccer match between Egypt and Algeria tonight. It took me sometime to succeed in publishing the story on the wall, so I will share with you my experience and how I solved it out in Coldfusion.
As I build my applications using the work of Andrew Duckett who created the Facebook Rest Client Component, I will start from FacebookFBMLCLient.cfc file which contains the methods that communicates with facebook APIs.
As I have used one of the three methods above which sounded the best as I guess, this example will be based on stream.publish method.
The first step is to add the following method to the FacebookFBMLCLient.cfc file:
<cffunction name="publishStream" access="public" output="false" returntype="any" hint="Publish on Wall">
<cfargument name="session_key" type="string" required="true" hint="the session id of the logged in user">
<cfargument name="to_ids" type="string" required="true" hint="ids of all the friends user has chosen">
<cfargument name="message" type="string" required="true" hint="message">
<cfargument name="attachment" type="Any" required="true" hint="JSON Object">
<cfargument name="action_links" type="Any" required="true" hint="JSON Object">
<!--- local vars --->
<cfset var params = StructNew() />
<!--- the api call --->
<cfset params["session_key"] = arguments.session_key />
<!--- <cfset params["uids"] = arguments.to_ids />--->
<cfset params["message"] = arguments.message />
<cfset params["attachment"] = arguments.attachment />
<cfset params["action_links"] = arguments.action_links />
<!--- Invoke stream.publish API --->
<cfset sendNoteVar = xmlToStructParam('facebook.stream.Publish',params) />
<cfreturn sendNoteVar />
</cffunction>
The second step is that you need permission from the users of the application to grant the method permission to publish on their walls, this can be done in many ways see this link, in my application I ask the permission from users when they submit the form, which I believe is the best way. So if you are using a form in your application you may get the permission to publish on users wall by By including the promptpermission attribute in the form as below:
<form name="Form" promptpermission="publish_stream" action="Action.cfm" method="post">
The third step is to call the publish stream method:
<cfset attachment = '{"properties":{"Votes":{"text":"Members Voted: (#eg# Votes for EGYPT)(#al# Votes for ALGERIA) (No Winner #equ#)","href":"#faceBookPath#/#appName#","rating":"rate"}},"media": [{"type":"image","src":"http://www.abusalah.info/fbapps/fbapp3/imgs/Algeria.jpg","href":"http://apps.facebook.com/algeria-egypt/"}]}'>
<cfset action_links = '[{"text":"Make Your Prediction","href":"#faceBookPath#/#appName#"}]'>
<cfset #FBMLClient.publishStream(session.fb_session_key,session.fb_uid,answer1,attachment,action_links)#>
The attachment and action_links must be in JSON format, any simple format mistake will prevent the attachment or the action_links from being published, so you should be careful.
Please note that I didn't use all options that can be published using Stream.Publish method, you may add more options to your code see the list of media and other options here.
I believe thats all what you need to publish to wall using the new facebook api's, if you need any help or have any question please add a comment to the article.
Nice post. Is there any chance you can add a link to download all the files you talk about? Thanks.
ReplyDeleteI will post a full tutorial with the code soon
ReplyDeleteHi,
ReplyDeleteThough it sounds good but bit tough to make it functional.If can you please provide a sample code regarding facebook wall publishing then it would be helpful for me.
I will upload a full example soon.
ReplyDeleteWould really like to see the full example. Great work Mustafa! /herve
ReplyDeleteIs there a way to post to many wall at the same time ?
ReplyDeletethanks
In your function call what is answer1? Also I cannot find the function 'xmlToStructParam' anywhere in FacebookRestClient.cfc - where are you getting it from? Trying to get this working. Thanks!
ReplyDeleteAnswer1 is a variable that is to be published on the wall, it is a string variable.
ReplyDeleteFor the xmlToStructParam it is a coldfusion function.
Is there any chance you can add a link to download all the files you talk about? Thanks.
ReplyDeletePlease go to this post and copy the post and save them as advised, the link is:
ReplyDeletehttp://blog.abusalah.info/2010/08/coldfusion-facebook-graph-api-publish.html
Thank you for your response..
ReplyDeleteIs there a way to post to many wall at the same time ?
ReplyDeleteYes you can, just go to this example:
ReplyDeletehttp://blog.abusalah.info/2010/08/coldfusion-facebook-graph-api-publish.html
now replace the code below:
----------------
With the code below:
Now this loop will publish to all ur friends walls.
it looks the code is not appearing in the comment contact me on mustafa at abusalah dot info
ReplyDeleteHi Mustafa, I am trying to use your code but I am getting this error:
ReplyDeleteVariable XMLTOSTRUCTPARAM is undefined.
I just have the .cfm file and I am calling the function and passing the parameters...what am I doing wrong?
This is an old method by now, please see this post: http://blog.abusalah.info/2010/08/coldfusion-facebook-graph-api-publish.html
ReplyDeleteThis is 100% working and up to date.