private void ConstructTestTemplates(out List<string> oneLineTemplates, out List<feedTemplate> shortStoryTemplates, out feedTemplate fullStoryTemplate)
 {
     string oneLineStoryTemplate = "{*actor*} has been playing.";
     string shortStoryTemplateTitle = "{*actor*} has been <a href='http://www.facebook.com/apps/application.php?id=xxx>Playing Poker!</a>";
     string shortStoryTemplateBody = "short story body";
     string fullStoryTemplateTitle = "{*actor*} has been <a href='http://www.facebook.com/apps/application.php?id=xxx>Playing Poker!</a>";
     string fullStoryTemplateBody = "full story body";
     oneLineTemplates = new List<string> { oneLineStoryTemplate };
     feedTemplate shortStoryTemplate = new feedTemplate { PreferredLayout = "1", TemplateBody = shortStoryTemplateBody, TemplateTitle = shortStoryTemplateTitle };
     shortStoryTemplates = new List<feedTemplate> { shortStoryTemplate };
     fullStoryTemplate = new feedTemplate { PreferredLayout = "1", TemplateBody = fullStoryTemplateBody, TemplateTitle = fullStoryTemplateTitle };
 }
        public void publishUserActionTest()
        {
            string oneLineStoryTemplate = "{*actor*} has been playing at {*host*}'s house.";
            string shortStoryTemplateTitle = "{*actor*} has been <a href='http://www.facebook.com/apps/application.php?id=xxx>Playing Poker!</a>";
            string shortStoryTemplateBody = "short story body from {*host*}'s house";
            string fullStoryTemplateTitle = "{*actor*} has been <a href='http://www.facebook.com/apps/application.php?id=xxx>Playing Poker!</a>";
            string fullStoryTemplateBody = "full story body from {*host*}'s house.";
            List<string> oneLineTemplates = new List<string> { oneLineStoryTemplate };
            feedTemplate shortStoryTemplate = new feedTemplate { PreferredLayout = "1", TemplateBody = shortStoryTemplateBody, TemplateTitle = shortStoryTemplateTitle };
            List<feedTemplate> shortStoryTemplates = new List<feedTemplate> { shortStoryTemplate };
            feedTemplate fullStoryTemplate = new feedTemplate { PreferredLayout = "1", TemplateBody = fullStoryTemplateBody, TemplateTitle = fullStoryTemplateTitle };

            var templateBundleId = _api.Feed.RegisterTemplateBundle(oneLineTemplates, shortStoryTemplates, fullStoryTemplate);
            List<long> friendTargets = new List<long> { Constants.FBSamples_friend1, Constants.FBSamples_friend2};
            Dictionary<string, string> body_data = new Dictionary<string, string> { { "host", "Run" } };

            var actual = _api.Feed.PublishUserAction(templateBundleId, body_data, friendTargets, null, Feed.PublishedStorySize.Short);
            Assert.IsTrue(actual);

            // TODO: find a way to deactivate the template bundle just created, since calls to feed.deactivateTemplateBundleById don't seem to
            // work. The error returned says that only the owner of a desktop app can deactivate template bundles, but this user should be the
            // owner of this app. Currently, we have to periodically go in to the Registered Templates Console and deactivate a bunch of templates
            // so that we don't go over our limit.
        }
        private void ContinuePublishUserActionTest()
        {
            string oneLineStoryTemplate = "{*actor*} has been playing at {*host*}'s house.";
            string shortStoryTemplateTitle = "{*actor*} has been <a href='http://www.facebook.com/apps/application.php?id=xxx>Playing Poker!</a>";
            string shortStoryTemplateBody = "short story body from {*host*}'s house";
            string fullStoryTemplateTitle = "{*actor*} has been <a href='http://www.facebook.com/apps/application.php?id=xxx>Playing Poker!</a>";
            string fullStoryTemplateBody = "full story body from {*host*}'s house.";
            List<string> oneLineTemplates = new List<string> { oneLineStoryTemplate };
            feedTemplate shortStoryTemplate = new feedTemplate { PreferredLayout = "1", TemplateBody = shortStoryTemplateBody, TemplateTitle = shortStoryTemplateTitle };
            List<feedTemplate> shortStoryTemplates = new List<feedTemplate> { shortStoryTemplate };
            feedTemplate fullStoryTemplate = new feedTemplate { PreferredLayout = "1", TemplateBody = fullStoryTemplateBody, TemplateTitle = fullStoryTemplateTitle };

            _api.Feed.RegisterTemplateBundleAsync(oneLineTemplates, shortStoryTemplates, fullStoryTemplate, OnRegisterForPublishUserActionCompleted, null);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            var t1 = WebConfigurationManager.AppSettings["TemplateID1"];
            var t2= WebConfigurationManager.AppSettings["TemplateID2"];
            var dict = new Dictionary<string, string>
            {
                {"application_name","Smiley.NET"},
                {"callback_url",callback},
                {"tab_default_name","Smile.NET"},
                {"profile_tab_url","mysmiles.aspx"},
                {"publish_action","Smile at!"},
                {"publish_url",callback + "handlers/otherPublishHandler.aspx"},
                {"publish_self_action","Smile!"},
                {"publish_self_url",callback + "handlers/publishHandler.aspx"},
                {"info_changed_url",callback + "handlers/infoHandler.aspx"},
                {"wide_mode","1"}
            };
            this.Api.Admin.SetAppProperties(dict);
            var one_line_story = new List <string>{"{*actor*} is feeling {*mood*} today"};
            var short_story = new List<feedTemplate>();
            var short_story_template = new feedTemplate
                                    {
                                        TemplateTitle = "{*actor*} is feeling so {*mood*} today",
                                        TemplateBody = "{*actor*} just wanted to let you know that he is so {*mood*} today",
                                        PreferredLayout = "1"
                                    };
            short_story.Add(short_story_template);

            var full_story = new feedTemplate
                                    {
                                        TemplateTitle = "{*actor*} is feeling very {*mood*} today",
                                        TemplateBody = "<div style=\"padding: 10px;width : 200px;height : 200px;margin: auto;text-align: center;border: black 1px;cursor: pointer;border: black solid 2px;background: orange;color: black;text-decoration: none;\"><div style=\"font-size: 60pt;font-weight: bold;padding: 40px;\">{*emote*}</div><div style=\"font-size: 20px; font-weight:bold;\">{*mood*}</div></div>"
                                    };
            if (string.IsNullOrEmpty(t1))
            {
                long bundle1id = this.Api.Feed.RegisterTemplateBundle(one_line_story, short_story, full_story);
                this.template1.Text = "Bundle 1 is empty = " + bundle1id;
            }
            else
            {
                this.template1.Text = "Bundle 1 is " + t1;

            }

            one_line_story = new List <string>{"{*actor*} just wanted to {*emote*} at {*target*} today"};
            short_story = new List<feedTemplate>();
            short_story_template = new feedTemplate
                                    {
                                        TemplateTitle = "{*actor*} just wanted to {*emote*} at {*target*} today",
                                        TemplateBody = "Always a great day to {*emoteaction*}",
                                        PreferredLayout = "1"
                                    };
            short_story.Add(short_story_template);

            full_story = new feedTemplate
                                    {
                                        TemplateTitle = "{*actor*} just wanted to {*emote*} at {*target*} today",
                                        TemplateBody = "Always a great day to {*emoteaction*}"
                                    };

            if (string.IsNullOrEmpty(t2))
            {
                long bundle2id = this.Api.Feed.RegisterTemplateBundle(one_line_story, short_story, full_story);
                this.template2.Text = "Bundle 2 is empty = " + bundle2id;
            }
            else
            {
                this.template2.Text = "Bundle 2 is " + t2;

            }

             var options  = new List<info_item>();
             options.Add(new info_item{label="Happy",image=callback + "images/smile0.jpg", sublabel= "",description="The original and still undefeated.", link="http://apps.facebook.com/"+suffix+"/smile.aspx?smile=1"});
             options.Add(new info_item{label="Indifferent",image=callback + "images/smile1.jpg", sublabel= "",description="meh....", link="http://apps.facebook.com/"+suffix+"/smile.aspx?smile=2"});
             options.Add(new info_item{label="Sad",image=callback + "images/smile2.jpg", sublabel= "",description="Oh my god! you killed my dog!", link="http://apps.facebook.com/"+suffix+"/smile.aspx?smile=3"});
             options.Add(new info_item { label = "Cool", image = callback + "images/smile3.jpg", sublabel = "", description = "Yeah. whatever", link = "http://apps.facebook.com/" + suffix + "/smile.aspx?smile=4"});
             this.Api.Profile.SetInfoOptions("My Smiles", options);
        }
        private long RegisterNewBundle()
        {
            string oneLineStoryTemplate = "{*actor*} has been playing.";
            string shortStoryTemplateTitle = "{*actor*} has been <a href='http://www.facebook.com/apps/application.php?id=xxx>Playing Poker!</a>";
            string shortStoryTemplateBody = "short story body";
            string fullStoryTemplateTitle = "{*actor*} has been <a href='http://www.facebook.com/apps/application.php?id=xxx>Playing Poker!</a>";
            string fullStoryTemplateBody = "full story body";
            List<string> oneLineTemplates = new List<string> { oneLineStoryTemplate };
            feedTemplate shortStoryTemplate = new feedTemplate { PreferredLayout = "1", TemplateBody = shortStoryTemplateBody, TemplateTitle = shortStoryTemplateTitle };
            List<feedTemplate> shortStoryTemplates = new List<feedTemplate> { shortStoryTemplate };
            feedTemplate fullStoryTemplate = new feedTemplate { PreferredLayout = "1", TemplateBody = fullStoryTemplateBody, TemplateTitle = fullStoryTemplateTitle };

            return _apiWeb.Feed.RegisterTemplateBundle(oneLineTemplates, shortStoryTemplates, fullStoryTemplate);
        }
        private long RegisterTemplateBundle(List<string> oneLineStoryTemplates, List<feedTemplate> shortStoryTemplates, feedTemplate fullStoryTemplate, IList<action_link> actionLinks, bool isAsync, RegisterTemplateBundleCallback callback, Object state)
        {
            var parameterList = new Dictionary<string, string> { { "method", "facebook.feed.registerTemplateBundle" } };

            Utilities.AddJSONArray(parameterList, "one_line_story_templates", oneLineStoryTemplates);

            var list = new List<string>();
            foreach (var item in shortStoryTemplates)
            {
                var dict = new Dictionary<string, string>{
                    {"template_title", item.TemplateTitle},
                    {"template_body", item.TemplateBody},
                    {"preferred_layout", item.PreferredLayout}
                };
                list.Add(JSONHelper.ConvertToJSONAssociativeArray(dict));
            }
            Utilities.AddJSONArray(parameterList, "short_story_templates", list);

            if (actionLinks != null)
            {
                var alist = new List<string>();
                foreach (action_link al in actionLinks)
                {
                    var dict = new Dictionary<string, string>{
                                {"text", al.text},
                                {"href", al.href}
                            };
                    alist.Add(JSONHelper.ConvertToJSONAssociativeArray(dict));
                }
                Utilities.AddJSONArray(parameterList, "action_links", alist);
            }

            var full_story_template = new Dictionary<string, string>();
            full_story_template.Add("template_title", fullStoryTemplate.TemplateTitle);
            full_story_template.Add("template_body", fullStoryTemplate.TemplateBody);
            Utilities.AddJSONAssociativeArray(parameterList, "full_story_template", full_story_template);

            if (isAsync)
            {
                SendRequestAsync<feed_registerTemplateBundle_response, long>(parameterList, !string.IsNullOrEmpty(Session.SessionKey), new FacebookCallCompleted<long>(callback), state);
                return 0;
            }

            var response = SendRequest<feed_registerTemplateBundle_response>(parameterList, !string.IsNullOrEmpty(Session.SessionKey));
            return response == null ? 0 : response.TypedValue;
        }
 /// <summary>
 /// Builds a template bundle around the specified templates, registers them on Facebook, and responds with a template bundle ID that can be used to identify your template bundle to other Feed-related API calls.
 /// </summary>
 /// <example>
 /// <code>
 /// private static void RunDemoAsync()
 /// {
 ///     Api api = new Api(new DesktopSession(Constants.ApplicationKey, Constants.ApplicationSecret, Constants.SessionSecret, Constants.SessionKey));
 ///
 ///     string oneLineStoryTemplate = "{*actor*} has been playing.";
 ///     string shortStoryTemplateTitle = "{*actor*} has been &lt;a href='http://www.facebook.com/apps/application.php?id=xxx&gt;testing!&lt;/a&gt;";
 ///     string shortStoryTemplateBody = "short story body";
 ///     string fullStoryTemplateTitle = "{*actor*} has been &lt;a href='http://www.facebook.com/apps/application.php?id=xxx&gt;testing!&lt;/a&gt;";
 ///     string fullStoryTemplateBody = "full story body";
 ///     List&lt;string&gt; oneLineTemplates = new List&lt;string&gt; { oneLineStoryTemplate };
 ///     feedTemplate shortStoryTemplate = new feedTemplate { PreferredLayout = "1", TemplateBody = shortStoryTemplateBody, TemplateTitle = shortStoryTemplateTitle };
 ///     List&lt;feedTemplate&gt; shortStoryTemplates = new List&lt;feedTemplate&gt; { shortStoryTemplate };
 ///     feedTemplate fullStoryTemplate = new feedTemplate { PreferredLayout = "1", TemplateBody = fullStoryTemplateBody, TemplateTitle = fullStoryTemplateTitle };
 ///     List&lt;action_link&gt; actionLinks = new List&lt;action_link&gt;();
 ///     actionLinks.Add(new action_link() { href = "http://www.facebook.com", text = "facebook link"});
 ///
 ///     api.Feed.RegisterTemplateBundleAsync(oneLineTemplates, shortStoryTemplates, fullStoryTemplate, actionLinks, AsyncDemoCompleted, null);
 /// }
 ///
 /// private static void AsyncDemoCompleted(long result, Object state, FacebookException e)
 /// {
 ///     var actual = result;
 /// }
 /// </code>
 /// </example>
 /// <param name="oneLineStoryTemplates">array containing one FBML template that can be used to render one line Feed stories</param>
 /// <param name="shortStoryTemplates">Array of short story templates</param>
 /// <param name="fullStoryTemplate">template for a single full story</param>
 /// <param name="actionLinks">Array of action link records</param>
 /// <param name="callback">The AsyncCallback delegate</param>
 /// <param name="state">An object containing state information for this asynchronous request</param>        
 /// <returns>This method returns an identifier that the developer can use to publish actual stories using that template bundle.</returns>
 public void RegisterTemplateBundleAsync(List<string> oneLineStoryTemplates, List<feedTemplate> shortStoryTemplates, feedTemplate fullStoryTemplate,
     IList<action_link> actionLinks, RegisterTemplateBundleCallback callback, Object state)
 {
     RegisterTemplateBundle(oneLineStoryTemplates, shortStoryTemplates, fullStoryTemplate, actionLinks, true, callback, state);
 }
 /// <summary>
 /// Builds a template bundle around the specified templates, registers them on Facebook, and responds with a template bundle ID that can be used to identify your template bundle to other Feed-related API calls.
 /// </summary>
 /// <example>
 /// <code>
 /// private static void RunDemoAsync()
 /// {
 ///     Api api = new Api(new DesktopSession(Constants.ApplicationKey, Constants.ApplicationSecret, Constants.SessionSecret, Constants.SessionKey));
 ///
 ///     string oneLineStoryTemplate = "{*actor*} has been playing.";
 ///     string shortStoryTemplateTitle = "{*actor*} has been &lt;a href='http://www.facebook.com/apps/application.php?id=xxx&gt;testing!&lt;/a&gt;";
 ///     string shortStoryTemplateBody = "short story body";
 ///     string fullStoryTemplateTitle = "{*actor*} has been &lt;a href='http://www.facebook.com/apps/application.php?id=xxx&gt;testing!&lt;/a&gt;";
 ///     string fullStoryTemplateBody = "full story body";
 ///     List&lt;string&gt; oneLineTemplates = new List&lt;string&gt; { oneLineStoryTemplate };
 ///     feedTemplate shortStoryTemplate = new feedTemplate { PreferredLayout = "1", TemplateBody = shortStoryTemplateBody, TemplateTitle = shortStoryTemplateTitle };
 ///     List&lt;feedTemplate&gt; shortStoryTemplates = new List&lt;feedTemplate&gt; { shortStoryTemplate };
 ///     feedTemplate fullStoryTemplate = new feedTemplate { PreferredLayout = "1", TemplateBody = fullStoryTemplateBody, TemplateTitle = fullStoryTemplateTitle };
 ///
 ///     api.Feed.RegisterTemplateBundleAsync(oneLineTemplates, shortStoryTemplates, fullStoryTemplate, AsyncDemoCompleted, null);
 /// }
 ///
 /// private static void AsyncDemoCompleted(long result, Object state, FacebookException e)
 /// {
 ///     var actual = result;
 /// }
 /// </code>
 /// </example>
 /// <param name="oneLineStoryTemplates">array containing one FBML template that can be used to render one line Feed stories</param>
 /// <param name="shortStoryTemplates">Array of short story templates</param>
 /// <param name="fullStoryTemplate">template for a single full story</param>
 /// <param name="callback">The AsyncCallback delegate</param>
 /// <param name="state">An object containing state information for this asynchronous request</param>        
 /// <returns>This method returns an identifier that the developer can use to publish actual stories using that template bundle.</returns>
 public void RegisterTemplateBundleAsync(List<string> oneLineStoryTemplates, List<feedTemplate> shortStoryTemplates, feedTemplate fullStoryTemplate, RegisterTemplateBundleCallback callback, Object state)
 {
     RegisterTemplateBundleAsync(oneLineStoryTemplates, shortStoryTemplates, fullStoryTemplate, null, callback, state);
 }
 /// <summary>
 /// Builds a template bundle around the specified templates, registers them on Facebook, and responds with a template bundle ID that can be used to identify your template bundle to other Feed-related API calls.
 /// </summary>
 /// <example>
 /// <code>
 /// Api api = new Api(new DesktopSession(Constants.ApplicationKey, Constants.ApplicationSecret, Constants.SessionSecret, Constants.SessionKey));
 ///
 /// string oneLineStoryTemplate = "{*actor*} has been playing.";
 /// string shortStoryTemplateTitle = "{*actor*} has been &lt;a href='http://www.facebook.com/apps/application.php?id=xxx&gt;testing!&lt;/a&gt;";
 /// string shortStoryTemplateBody = "short story body";
 /// string fullStoryTemplateTitle = "{*actor*} has been &lt;a href='http://www.facebook.com/apps/application.php?id=xxx&gt;testing!&lt;/a&gt;";
 /// string fullStoryTemplateBody = "full story body";
 /// List&lt;string&gt; oneLineTemplates = new List&lt;string&gt; { oneLineStoryTemplate };
 /// feedTemplate shortStoryTemplate = new feedTemplate { PreferredLayout = "1", TemplateBody = shortStoryTemplateBody, TemplateTitle = shortStoryTemplateTitle };
 /// List&lt;feedTemplate&gt; shortStoryTemplates = new List&lt;feedTemplate&gt; { shortStoryTemplate };
 /// feedTemplate fullStoryTemplate = new feedTemplate { PreferredLayout = "1", TemplateBody = fullStoryTemplateBody, TemplateTitle = fullStoryTemplateTitle };
 /// List&lt;action_link&gt; actionLinks = new List&lt;action_link&gt;();
 /// actionLinks.Add(new action_link() { href = "http://www.facebook.com", text = "facebook link" });
 ///
 /// var result = api.Feed.RegisterTemplateBundle(oneLineTemplates, shortStoryTemplates, fullStoryTemplate, actionLinks);
 /// </code>
 /// </example>
 /// <param name="oneLineStoryTemplates">array containing one FBML template that can be used to render one line Feed stories</param>
 /// <param name="shortStoryTemplates">Array of short story templates</param>
 /// <param name="fullStoryTemplate">template for a single full story</param>
 /// <param name="actionLinks">Array of action link records</param>
 /// <returns>This method returns an identifier that the developer can use to publish actual stories using that template bundle.</returns>
 public long RegisterTemplateBundle(List<string> oneLineStoryTemplates, List<feedTemplate> shortStoryTemplates, feedTemplate fullStoryTemplate, IList<action_link> actionLinks)
 {
     return RegisterTemplateBundle(oneLineStoryTemplates, shortStoryTemplates, fullStoryTemplate, actionLinks, false, null, null);
 }
 /// <summary>
 /// Builds a template bundle around the specified templates, registers them on Facebook, and responds with a template bundle ID that can be used to identify your template bundle to other Feed-related API calls.
 /// </summary>
 /// <example>
 /// <code>
 /// Api api = new Api(new DesktopSession(Constants.ApplicationKey, Constants.ApplicationSecret, Constants.SessionSecret, Constants.SessionKey));
 ///
 /// string oneLineStoryTemplate = "{*actor*} has been playing.";
 /// string shortStoryTemplateTitle = "{*actor*} has been &lt;a href='http://www.facebook.com/apps/application.php?id=xxx&gt;testing!&lt;/a&gt;";
 /// string shortStoryTemplateBody = "short story body";
 /// string fullStoryTemplateTitle = "{*actor*} has been &lt;a href='http://www.facebook.com/apps/application.php?id=xxx&gt;testing!&lt;/a&gt;";
 /// string fullStoryTemplateBody = "full story body";
 /// List&lt;string&gt; oneLineTemplates = new List&lt;string&gt; { oneLineStoryTemplate };
 /// feedTemplate shortStoryTemplate = new feedTemplate { PreferredLayout = "1", TemplateBody = shortStoryTemplateBody, TemplateTitle = shortStoryTemplateTitle };
 /// List&lt;feedTemplate&gt; shortStoryTemplates = new List&lt;feedTemplate&gt; { shortStoryTemplate };
 /// feedTemplate fullStoryTemplate = new feedTemplate { PreferredLayout = "1", TemplateBody = fullStoryTemplateBody, TemplateTitle = fullStoryTemplateTitle };
 ///
 /// var result = api.Feed.RegisterTemplateBundle(oneLineTemplates, shortStoryTemplates, fullStoryTemplate);
 /// </code>
 /// </example>
 /// <param name="oneLineStoryTemplates">array containing one FBML template that can be used to render one line Feed stories</param>
 /// <param name="shortStoryTemplates">Array of short story templates</param>
 /// <param name="fullStoryTemplate">template for a single full story</param>
 /// <returns>This method returns an identifier that the developer can use to publish actual stories using that template bundle.</returns>
 public long RegisterTemplateBundle(List<string> oneLineStoryTemplates, List<feedTemplate> shortStoryTemplates, feedTemplate fullStoryTemplate)
 {
     return RegisterTemplateBundle(oneLineStoryTemplates, shortStoryTemplates, fullStoryTemplate, null);
 }