Facebook Open Stream API

Apr 28, 2009 at 7:29 AM
Are there any plans to implement this new API into the FDT?
Apr 28, 2009 at 4:36 PM
We're talking about it. No time line yet. I'll give the "standard open source reply" as well. The project is open source, so anyone can add support for the Open Stream API. If you need it ASAP, please contribute!
May 2, 2009 at 10:04 PM
I'm just doing it now.

and have allready a basically working example.
took me a little bit to figure out how this should be done.

i am also willing to contribute the whole feature to the project.
just if:
.) i get some questions answered (for example have a weird exception when i authenticate for the stream)
.) someone gives me a overview about the project status.

and then maybe, i would also willing to help keep this alive.

open for contact.
May 5, 2009 at 3:51 PM
It would be great if we got stream.publish incorporated right away. When will this be available?
May 6, 2009 at 5:18 PM
when i get access to the repository.
to make the changes.
and depending on how much i have to change to submit it.
the current architecture is not the greatest of this project....
May 7, 2009 at 7:23 PM

Thanks for the effort.  If it's not too much trouble, would you mind submitting your changes as a patch?  We'll take a look at them to see what would be needed to integrate the changes into the toolkit. 

With respect to the archetecture, I'm pretty familiar with it.  Let me know if you'd like me to walk you through it sometime and I'll set up a live meeting.

May 11, 2009 at 5:50 PM
Edited May 11, 2009 at 8:40 PM

I couldnt wait for this update so I went ahead and did it myself.  If anyone is interested here it is.


using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using facebook.Schema;
using facebook.Utility;
using System.IO;
using System.Web;

namespace facebook
    /// <summary>
    /// stream methods
    /// </summary>
    public class stream
        #region Constructor
        private readonly API _api;
        /// <summary>
        /// Public constructor for facebook.stream
        /// </summary>
        /// <param name="parent">Needs a connected API object for making requests</param>
        public stream(API parent)
            _api = parent;

        #region Facebook API
        /// <summary>
        /// This method publishes a post into the stream on the user's Wall and News Feed. This post also appears in the user's friends' streams (their News Feeds).
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="target_id">The target_id.</param>
        /// <param name="uid">The uid.</param>
        /// <returns></returns>
        public string publish(string message, string target_id, string uid, Attachment attachment, Dictionary<string,string> action_links)
            var parameterList = new Dictionary<string, string> { { "method", "facebook.stream.publish" } };
            _api.AddOptionalParameter(parameterList, "message", message);
            _api.AddOptionalParameter(parameterList, "target_id", target_id);
            _api.AddOptionalParameter(parameterList, "uid", uid);
            var dict = new Dictionary<string, string>{
                    {"name", attachment.name},
                    {"href", attachment.href},
                    {"caption", attachment.caption},
                    {"description", attachment.description}

            var list = new List<string>();
            foreach (var item in attachment.media)
                if (item is Image)
                    var media = item as Image;

                    var mediaDict = new Dictionary<string, string>{
                        {"type", media.type},
                        {"src", media.src},
                        {"href", media.href}

            _api.AddJSONArray(dict, "media", list);

            Dictionary<string, string> propertyDict = new Dictionary<string, string>();
            foreach (var item in attachment.properties)
                if (item is PropertyLink)
                    PropertyLink link = item as PropertyLink;

                    var linkDict = new Dictionary<string, string>{
                        {"text", link.text},
                        {"href", link.href}

                    propertyDict.Add(item.key, JSONHelper.ConvertToJSONAssociativeArray(linkDict));
                    propertyDict.Add(item.key, item.value);

            dict.Add("properties", JSONHelper.ConvertToJSONAssociativeArray(propertyDict));

            _api.AddJSONAssociativeArray(parameterList, "attachment", dict);

            list = new List<string>();

            foreach (var item in action_links)
                var linkDict = new Dictionary<string, string>{
                    {"text", item.Key},
                    {"href", item.Value}


            _api.AddJSONArray(parameterList, "action_links", list);

            var response = _api.SendRequest(parameterList);

            return stream_publish_response.Parse(response).TypedValue;

        public class Attachment
            public string name { get; set; }
            public string href { get; set; }
            public string caption { get; set; }
            public string description { get; set; }
            public List<Media> media { get; set; }
            public List<Property> properties { get; set; }

        public class Media
            public string type { get; set; }

        public class Image : Media
            public Image()
                this.type = "image";

            public string src { get; set; }
            public string href { get; set; }

        public class Property
            public string key { get; set; }
            public string value { get; set; }

        public class PropertyLink : Property
            public string text { get; set; }
            public string href { get; set; }


Here is my call.


  facebook.stream stream = new facebook.stream(this.API);

        facebook.stream.Attachment attachment = new facebook.stream.Attachment();
        attachment.name = "Bar Tab";
        attachment.href = "http://apps.facebook.com/bartabfb";
        attachment.caption = "Mike sent you a Margarita from Salty Senoritas!";
        attachment.description = "Sign up with BarTab today to beg your friends for a real drink.";
        attachment.media = new List<facebook.stream.Media>();

        facebook.stream.Image image = new facebook.stream.Image();
        image.src = "http://media.dev.mybartab.com/generic_marg.png";
        image.href = "http://apps.facebook.com/bartabfb";


        image = new facebook.stream.Image();
        image.src = "http://media.dev.mybartab.com/2ea0e17f-a338-4eab-915b-9ed0b6206b7c.jpg";
        image.href = "http://apps.facebook.com/bartabfb";


        attachment.properties = new List<facebook.stream.Property>();

        facebook.stream.Property property = new facebook.stream.Property();
        property.key = "Ratings";
        property.value = "5 stars";


        facebook.stream.PropertyLink link = new facebook.stream.PropertyLink();
        link.key = "category";
        link.text = "humor";
        link.href = "http://apps.facebook.com/bartabfb";


        Dictionary<string, string> action_links = new Dictionary<string, string>();
        action_links.Add("Bartab", "http://apps.facebook.com/bartabfb");
        action_links.Add("Salty Senoritas", "http://apps.facebook.com/bartabfb");

        stream.publish("test", "515434240", string.Empty, attachment, action_links);

May 12, 2009 at 7:57 PM

this looks great - thanks for sharing! These may be newbie problems, but I'm having some issues...

'facebook.API' does not contain a defintion for 'AddOptionalParameter'

'facebook.API' does not contain a defintion for 'AddJSONArray'

'facebook.API' does not contain a defintion for 'AddJSONAssociativeArray'

'facebook.API' does not contain a defintion for 'AddJSONArray'


The name 'stream_publish_response' does not exist in the current context.

Anyone else getting this?

May 14, 2009 at 2:45 PM
Edited May 14, 2009 at 2:53 PM

i guess cblaze22 forgot to show code from LinqToXsdSource.cs for "stream_publish_response".


May 14, 2009 at 5:53 PM

Thanks for posting this.  I am in the process of adding all of the stream functionality (I know its a little late).  I had implemented this function (in a very similar fashion).  I had one bug with the media stuff that I was able to track down thanks to your code above.

Working implementation of the stream stuff should be checked in later today and packed in  a release in the next week or so.

More to come.  Thanks again.

@jypelton - sounds like potentially don't have the 2.0 version of the API.cs.  Also, Pash is correct on why the stream_publish_response is not recognized.  I will be checking in code this afternoon hopefully with a working version of all the stream apis.

May 28, 2009 at 6:57 PM

I didnt add that as it would take up way to much room.  If you are a developer its pretty easy to figure out as you would just copy an existing one and make the changes.

May 29, 2009 at 3:07 PM

Not too helpfull to most of developers. Why to show half of code if u r not going to show the rest?

Aug 25, 2009 at 7:11 AM


I need to attach an image to stream.publish()  method of facebook API.

i could do that ...

code is below..

attachment attach = new attachment();
            attach.caption = "Caption for attachment";
            attach.description = "Description for attachment";
            attach.href = "http://www.joemagner.com";
            attach.name = "Hopefully this works";
            attachment_media attach_media = new attachment_media();
            attach_media.type = attachment_media_type.image;
            attachment_media_image image = new attachment_media_image();
            image.type = attachment_media_type.image;
            image.href = "";
            image.src = ""; //img1.Src;
            List<attachment_media> attach_media_list = new List<attachment_media>();
            attach_media_list.Add(image); attach.media = attach_media_list;
            attachment_property attach_prop = new attachment_property();
            attachment_category attach_cat = new attachment_category();
            attach_cat.text = "Sample";
            attach_cat.href = "#";
            attach_prop.category = attach_cat;
            attach_prop.ratings = "5 stars";
            attach.properties = attach_prop;


but i need to give the image.src ="local path" Is that possible?

please give ans