Skip to main content

The New Facebook Wall Publishing method Stream.publish

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.

Comments

  1. Nice post. Is there any chance you can add a link to download all the files you talk about? Thanks.

    ReplyDelete
  2. I will post a full tutorial with the code soon

    ReplyDelete
  3. Hi,
    Though 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.

    ReplyDelete
  4. I will upload a full example soon.

    ReplyDelete
  5. Would really like to see the full example. Great work Mustafa! /herve

    ReplyDelete
  6. Is there a way to post to many wall at the same time ?

    thanks

    ReplyDelete
  7. 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!

    ReplyDelete
  8. Answer1 is a variable that is to be published on the wall, it is a string variable.

    For the xmlToStructParam it is a coldfusion function.

    ReplyDelete
  9. Is there any chance you can add a link to download all the files you talk about? Thanks.

    ReplyDelete
  10. Please go to this post and copy the post and save them as advised, the link is:
    http://blog.abusalah.info/2010/08/coldfusion-facebook-graph-api-publish.html

    ReplyDelete
  11. Is there a way to post to many wall at the same time ?

    ReplyDelete
  12. Yes you can, just go to this example:

    http://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.

    ReplyDelete
  13. it looks the code is not appearing in the comment contact me on mustafa at abusalah dot info

    ReplyDelete
  14. Hi Mustafa, I am trying to use your code but I am getting this error:
    Variable XMLTOSTRUCTPARAM is undefined.

    I just have the .cfm file and I am calling the function and passing the parameters...what am I doing wrong?

    ReplyDelete
  15. This is an old method by now, please see this post: http://blog.abusalah.info/2010/08/coldfusion-facebook-graph-api-publish.html

    This is 100% working and up to date.

    ReplyDelete

Post a Comment

Popular posts from this blog

Top Google Adsense Alternatives

Google Adsense is a web tool that allows publishers in the Google Network of content sites to automatically serve text, image, video, and rich media adverts that are targeted to site content and audience. These adverts are administered, sorted, and maintained by Google, and they can generate revenue on either a per-click or per-impression basis.  Google servers advertisers using google adwords platform, while adsense is the publishers platform. Google Adsense is the top Ad Publishers platform over the web ranking number one in web advertising industry. Adsense offers contextual advertisements that covers web sites, blogs, games, videos, mobile browsing etc. What made Google Adsense no. 1 is the reliability, stability, variety of services and large number of publishers including google it self. Also google has a fair platform that detects invalid clicks so google successfully protects its advertisers and also offers its best publishers top CPC. Two reasons are behin...

The Semantic Web

Semantic Web aims to create a meaning and define inter-relationship for information available on the web In the early stages of the World Wide Web (web) it was necessary to develop standards to view web content (HTML language) and to create communication channels (N-Tier applications, email, ftp, etc.). As the web started to be the world’s largest knowledge base, accessible world wide, it became important to develop tools to transfer knowledge between cultures. However, it is still not possible for applications and agents to interoperate with other applications and agents without having a predefined, human created common framework of the meaning of the information being transferred on both sides. Semantic Web (SW) alleviates this problem by providing a common framework that allows data to be shared and reused across application, enterprise, and community boundaries [W3C Semantic Web, 2019]. A clear example on SW application is schema.org. Google, Bing, Yahoo use schema...

Arabs In London

I was not able to watch Arabs in London episodes during the last holy month of Ramadan. I watched it recently on MBC. I was really impressed by the performance of some actors and actresses. The most impressive one was Mais Hamdan who was able to present the Palestinian accent efficiently. This TV series was written and directed by Anwar Qawadri a Syrian director who studied and lived in London. The below video is about 8 minutes show when Sami finds out that his friend Eddy (Adnan) passed away.