/// <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> /// <example> /// <code> /// Api api = new Api(new DesktopSession(Constants.ApplicationKey, Constants.ApplicationSecret, Constants.SessionSecret, Constants.SessionKey)); /// attachment attachment = new attachment(); /// attachment.caption = "facebook.com"; /// attachment.name = "Publish Test"; /// attachment.href = "http://www.facebook.com"; /// attachment.description = "a sample description"; /// /// attachment.properties = new attachment_property() /// { /// category = new attachment_category() /// { /// href = "http://www.facebook.com/mycategory/sample", /// text = "sample category" /// }, /// ratings = "5 stars" /// }; /// /// attachment.media = new List<attachment_media>(){new attachment_media_image() /// { /// src = "http://facebook.com/myapp/logo.jpg", /// href = "http://www.facebook.com/myapp" /// }}; /// /// var result = api.Stream.Publish("Publishing to stream with attachment", attachment, null, null, 0); /// </code> /// </example> /// <param name="message">The message the user enters for the post at the time of publication.</param> /// <param name="attachment">An object containing the text of the post, relevant links, a media type (image, video, mp3, flash), as well as any other key/value pairs you may want to add. See Facebook API for more details. Note: If you want to use this call to update a user's status, don't pass an attachment; the content of the message parameter will become the user's new status and will appear at the top of the user's profile.</param> /// <param name="actionLinks">A List of action link objects, containing the link text and a hyperlink.</param> /// <param name="target_id">The ID of the user or the Page where you are publishing the content. If you specify a target_id, the post appears on the Wall of the target user, not on the Wall of the user who published the post. This mimics the action of posting on a friend's Wall on Facebook itself.</param> /// <param name="uid">The user ID or Page ID of the user or Page publishing the post. If this parameter is not specified, then it defaults to the session user. Note: This parameter applies only to Web applications. Facebook ignores this parameter if it is passed by a desktop application.</param> /// <returns>This call returns a post_id string containing the ID of the stream item upon success. If the call fails, it returns an error code instead.</returns> public string Publish(string message, attachment attachment, IList<action_link> actionLinks, string target_id, long uid) { return Publish(message, attachment, actionLinks, target_id, uid, false, null, null); }
private string Publish(string message, attachment attachment, IList<action_link> action_links, string target_id, long uid, bool isAsync, PublishCallback callback, Object state) { var parameterList = new Dictionary<string, string> { { "method", "facebook.stream.publish" } }; Utilities.AddOptionalParameter(parameterList, "message", message); if (attachment != null) { var mediaList = new List<string>(); var prop = new Dictionary<string, string>(); if (attachment.properties != null) { foreach (var item in attachment.properties) { prop.Add(item.name, item.value.ToString()); } } if (attachment.media != null) { foreach (var item in attachment.media) { var media = new Dictionary<string, string>{ {"type", item.type.ToString()} }; if (item.type == attachment_media_type.image) { var image = item as attachment_media_image; media.Add("src", image.src); media.Add("href", image.href); } else if (item.type == attachment_media_type.flash) { var flash = item as attachment_media_flash; media.Add("swfsrc", flash.swfsrc); media.Add("imgsrc", flash.imgsrc); media.Add("width", flash.width.ToString()); media.Add("height", flash.height.ToString()); media.Add("expanded_width", flash.expanded_width.ToString()); media.Add("expanded_height", flash.expanded_height.ToString()); } else if (item.type == attachment_media_type.mp3) { var mp3 = item as attachment_media_mp3; media.Add("src", mp3.src); media.Add("title", mp3.title); media.Add("artist", mp3.artist); media.Add("album", mp3.album); } else { var video = item as attachment_media_video; media.Add("video_src", video.video_src); media.Add("preview_img", video.preview_img); media.Add("video_link", video.video_link); media.Add("video_title", video.video_title); } mediaList.Add(JSONHelper.ConvertToJSONAssociativeArray(media)); } } var dict = new Dictionary<string, string>{ {"name", attachment.name}, {"href", attachment.href}, {"caption", attachment.caption}, {"description", attachment.description}, {"properties", JSONHelper.ConvertToJSONAssociativeArray(prop)}, {"media", JSONHelper.ConvertToJSONArray(mediaList)}, {"latitude", attachment.latitude}, {"longitude", attachment.longitude} }; Utilities.AddOptionalParameter(parameterList, "attachment", JSONHelper.ConvertToJSONAssociativeArray(dict)); } if (action_links != null) { var list = new List<string>(); foreach (var item in action_links) { var dict = new Dictionary<string, string>{ {"text", item.text}, {"href", item.href} }; list.Add(JSONHelper.ConvertToJSONAssociativeArray(dict)); } Utilities.AddJSONArray(parameterList, "action_links", list); } Utilities.AddOptionalParameter(parameterList, "target_id", target_id); Utilities.AddOptionalParameter(parameterList, "uid", uid); if (isAsync) { SendRequestAsync<stream_publish_response, string>(parameterList, uid <=0, new FacebookCallCompleted<string>(callback), state); return null; } var response = SendRequest<stream_publish_response>(parameterList, uid <= 0); return response == null ? null : response.TypedValue; }
public void publishTest4() { attachment attachment = new attachment(); attachment.caption = "www.youtube.com"; attachment.name = "ninja cat"; attachment.href = "http://www.youtube.com/watch?v=muLIPWjks_M"; attachment.description = "a sneaky cat"; attachment.properties = new List<attachment_property>() { new attachment_property { name = "category", value = new attachment_property_value { href = "http://www.youtube.com/browse?s=mp&t=t&c=15", text = "humor" } }, new attachment_property { name = "ratings", value = new attachment_property_value { text = "5 stars" } } }; attachment.media = new List<attachment_media>(){new attachment_media_video() { video_src = "http://www.youtube.com/v/fzzjgBAaWZw&hl=en&fs=1", preview_img="http://img.youtube.com/vi/muLIPWjks_M/default.jpg?h=100&w=200&sigh=__wsYqEz4uZUOvBIb8g-wljxpfc3Q=", video_link = "http://www.youtube.com/watch?v=muLIPWjks_M", video_title = "ninja cat" }}; var link = new action_link(); link.href = "http://www.youtube.com/my_videos_upload"; link.text = "Upload a video"; var links = new List<action_link>() { link }; var actual = _api.Stream.Publish("Watch this video!", attachment, links, null, 0); Assert.IsNotNull(actual); }
/// <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> /// <example> /// <code> /// private static void RunDemoAsync() /// { /// Api api = new Api(new DesktopSession(Constants.ApplicationKey, Constants.ApplicationSecret, Constants.SessionSecret, Constants.SessionKey)); /// attachment attachment = new attachment(); /// attachment.caption = "facebook.com"; /// attachment.name = "Publish Test"; /// attachment.href = "http://www.facebook.com"; /// attachment.description = "a sample description"; /// /// attachment.properties = new attachment_property() /// { /// category = new attachment_category() /// { /// href = "http://www.facebook.com/mycategory/sample", /// text = "sample category" /// }, /// ratings = "5 stars" /// }; /// /// attachment.media = new List<attachment_media>(){new attachment_media_image() /// { /// src = "http://facebook.com/myapp/logo.jpg", /// href = "http://www.facebook.com/myapp" /// }}; /// /// api.Stream.PublishAsync("Publishing to stream with attachment", attachment, null, null, 0, AsyncDemoCompleted, null); /// } /// /// private static void AsyncDemoCompleted(string result, Object state, FacebookException e) /// { /// var actual = result; /// } /// </code> /// </example> /// <param name="message">The message the user enters for the post at the time of publication.</param> /// <param name="attachment">An object containing the text of the post, relevant links, a media type (image, video, mp3, flash), as well as any other key/value pairs you may want to add. See Facebook API for more details. Note: If you want to use this call to update a user's status, don't pass an attachment; the content of the message parameter will become the user's new status and will appear at the top of the user's profile.</param> /// <param name="actionLinks">A List of action link objects, containing the link text and a hyperlink.</param> /// <param name="target_id">The ID of the user or the Page where you are publishing the content. If you specify a target_id, the post appears on the Wall of the target user, not on the Wall of the user who published the post. This mimics the action of posting on a friend's Wall on Facebook itself.</param> /// <param name="uid">The user ID or Page ID of the user or Page publishing the post. If this parameter is not specified, then it defaults to the session user. Note: This parameter applies only to Web applications. Facebook ignores this parameter if it is passed by a desktop application.</param> /// <param name="callback">The AsyncCallback delegate</param> /// <param name="state">An object containing state information for this asynchronous request</param> /// <returns>This call returns a post_id string containing the ID of the stream item upon success. If the call fails, it returns an error code instead.</returns> public void PublishAsync(string message, attachment attachment, IList<action_link> actionLinks, string target_id, long uid, PublishCallback callback, Object state) { Publish(message, attachment, actionLinks, target_id, uid, true, callback, state); }
public void publishTest3() { attachment attachment = new attachment(); attachment.caption = "www.icanhascheezburger.com"; attachment.name = "I am bursting with joy"; attachment.href = "http://icanhascheezburger.com/2009/04/22/funny-pictures-bursting-with-joy/"; attachment.description = "a funny looking cat"; attachment.properties = new List<attachment_property>() { new attachment_property { name = "category", value = new attachment_property_value { href = "http://www.icanhascheezburger.com/category/humor", text = "humor" } }, new attachment_property { name = "ratings", value = new attachment_property_value { text = "5 stars" } } }; attachment.media = new List<attachment_media>(){new attachment_media_image() { src = "http://icanhascheezburger.files.wordpress.com/2009/03/funny-pictures-your-cat-is-bursting-with-joy1.jpg", href = "http://icanhascheezburger.com/2009/04/22/funny-pictures-bursting-with-joy/" }}; var link = new action_link(); link.href= "http://mine.icanhascheezburger.com/default.aspx?tiid=1192742&recap=1#step2"; link.text = "Recaption this"; var links = new List<action_link>(){link}; var actual = _api.Stream.Publish("testing stream.publish with image attachment", attachment, links, null, 0); Assert.IsNotNull(actual); }