protected void Page_Load(object sender, EventArgs e) { if (!string.IsNullOrEmpty(Request.Params["picked"])) { var picked = int.Parse(Request.Params["picked"]); var basePage = new BasePage(); var moods = basePage.getOtherMoods(); var canvas = string.Format("http://apps.facebook.com/{0}/mysmiles.aspx", suffix); var templateData = JSONHelper.ConvertToJSONAssociativeArray( new Dictionary <string, string> { { "emote", moods.ElementAt(picked).Value }, { "emoteaction", moods.ElementAt(picked).Key } }); var feed = JSONHelper.ConvertToJSONAssociativeArray( new Dictionary <string, string> { { "template_id", basePage.FeedTemplate2.ToString() }, { "template_data", templateData } }); var content = JSONHelper.ConvertToJSONAssociativeArray( new Dictionary <string, string> { { "feed", feed }, { "next", canvas } }); var data = JSONHelper.ConvertToJSONAssociativeArray( new Dictionary <string, string> { { "method", "multiFeedStory" }, { "content", content } }); json = data; } else { throw new Exception("no smile picked"); } }
internal void AddJSONAssociativeArray(IDictionary <string, string> dict, string key, Dictionary <string, string> value) { if (value != null && value.Count > 0) { dict.Add(key, JSONHelper.ConvertToJSONAssociativeArray(value)); } }
/// <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. You need to register at least one bundle for each of your applications, if you have more than one. /// </summary> /// <param name="oneLineStoryTemplates"></param> /// <param name="fullStoryTemplate"></param> /// <param name="shortStoryTemplates"></param> public long registerTemplateBundle(List <string> oneLineStoryTemplates, List <feedTemplate> shortStoryTemplates, feedTemplate fullStoryTemplate) { var parameterList = new Dictionary <string, string> { { "method", "facebook.feed.registerTemplateBundle" } }; _api.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)); } _api.AddJSONArray(parameterList, "short_story_templates", list); var full_story_template = new Dictionary <string, string>(); full_story_template.Add("template_title", fullStoryTemplate.TemplateTitle); full_story_template.Add("template_body", fullStoryTemplate.TemplateBody); _api.AddJSONAssociativeArray(parameterList, "full_story_template", full_story_template); var response = _api.SendRequest(parameterList); return(!string.IsNullOrEmpty(response) ? feed_registerTemplateBundle_response.Parse(response).TypedValue : 0); }
internal void AddRequiredParameter(IDictionary <string, string> dict, string key, IList <DataAssociation> assocs) { if (!(assocs == null)) { Dictionary <string, string> tempDict; StringBuilder sb = new StringBuilder(assocs.Count * 200); foreach (var da in assocs) { tempDict = new Dictionary <string, string> { { "assoc_time", DateHelper.ConvertDateToDouble(da.assoc_time).ToString() }, { "data", da.data }, { "id1", da.id1.ToString() }, { "id2", da.id2.ToString() }, { "name", da.name } }; sb.Append(JSONHelper.ConvertToJSONAssociativeArray(tempDict)); } AddRequiredParameter(dict, key, sb.ToString()); } else { throw new Exception(string.Format("Error: Parameter '{0}' is required.", key)); } }
private bool SetInfoOptions(string field, List <info_item> options, bool isAsync, SetInfoCallback callback, Object state) { var parameterList = new Dictionary <string, string> { { "method", "facebook.profile.setInfoOptions" } }; Utilities.AddRequiredParameter(parameterList, "field", field); var list = new List <string>(); foreach (var item in options) { var dict = new Dictionary <string, string> { { "label", item.label }, { "sublabel", item.sublabel }, { "link", item.link }, { "image", item.image }, { "description", item.description } }; list.Add(JSONHelper.ConvertToJSONAssociativeArray(dict)); } Utilities.AddJSONArray(parameterList, "options", list); if (isAsync) { SendRequestAsync <profile_setInfoOptions_response, bool>(parameterList, !string.IsNullOrEmpty(Session.SessionKey), new FacebookCallCompleted <bool>(callback), state); return(true); } var response = SendRequest <profile_setInfoOptions_response>(parameterList, !string.IsNullOrEmpty(Session.SessionKey)); return(response == null ? false : response.TypedValue); }
private long UploadNativeStrings(List <native_string> native_strings, bool isAsync, UploadNativeStringsCallback callback, Object state) { var parameterList = new Dictionary <string, string> { { "method", "facebook.intl.uploadNativeStrings" } }; var translationList = new List <string>(); foreach (var item in native_strings) { var translation = new Dictionary <string, string> { { "text", item.text }, { "description", item.description } }; translationList.Add(JSONHelper.ConvertToJSONAssociativeArray(translation)); } Utilities.AddRequiredParameter(parameterList, "native_strings", JSONHelper.ConvertToJSONArray(translationList)); if (isAsync) { SendRequestAsync <intl_uploadNativeStrings_response, long>(parameterList, !string.IsNullOrEmpty(Session.SessionKey), new FacebookCallCompleted <long>(callback), state); return(0); } var response = SendRequest <intl_uploadNativeStrings_response>(parameterList, !string.IsNullOrEmpty(Session.SessionKey)); return(response == null ? -1 : response.TypedValue); }
public bool setInfoOptions(string field, List <info_item> options) { var parameterList = new Dictionary <string, string> { { "method", "facebook.profile.setInfoOptions" } }; _api.AddRequiredParameter(parameterList, "field", field); var list = new List <string>(); foreach (var item in options) { var dict = new Dictionary <string, string> { { "label", item.label }, { "sublabel", item.sublabel }, { "link", item.link }, { "image", item.image }, { "description", item.description } }; list.Add(JSONHelper.ConvertToJSONAssociativeArray(dict)); } _api.AddJSONArray(parameterList, "options", list); var response = _api.SendRequest(parameterList); return(!string.IsNullOrEmpty(response) ? profile_setInfoOptions_response.Parse(response).TypedValue : false); }
protected void Page_Load(object sender, EventArgs e) { var basePage = new BasePage(); var moods = basePage.getMoods(); if (!string.IsNullOrEmpty(Request.Params["method"]) && Request.Params["method"] == "publisher_getFeedStory") { //TODO: need to figure out how to pull picked out of this var picked = 0; //int.Parse(Request.Params["app_params"]); var canvas = string.Format("http://apps.facebook.com/{0}/mysmiles.aspx", suffix); var image = string.Format("{0}images/smile{1}.jpg", callback, picked); var images = JSONHelper.ConvertToJSONAssociativeArray(new Dictionary <string, string> { { "src", image }, { "href", canvas } }); var templateData = JSONHelper.ConvertToJSONAssociativeArray( new Dictionary <string, string> { { "mood", moods.ElementAt(picked).Value }, { "emote", moods.ElementAt(picked).Key }, { "images", images }, { "mood_src", image } }); var feed = JSONHelper.ConvertToJSONAssociativeArray( new Dictionary <string, string> { { "template_id", basePage.FeedTemplate1.ToString() }, { "template_data", templateData } }); var content = JSONHelper.ConvertToJSONAssociativeArray( new Dictionary <string, string> { { "feed", feed } }); var data = JSONHelper.ConvertToJSONAssociativeArray( new Dictionary <string, string> { { "method", "publisher_getFeedStory" }, { "content", content } }); json = data; } else if (!string.IsNullOrEmpty(Request.Params["method"]) && Request.Params["method"] == "publisher_getInterface") { //TODO: need to figure out how to pull picked out of this var fbml = FBMLControlRenderer.RenderFBML <string>(string.Format("~/controls/PublisherHeader.ascx"), callback).Replace("\n", ""); //var fbml = @"<style> //</style>"; //fbml += "test"; fbml += string.Format("<form>{0}<input type=\"hidden\" id=\"picked\" name=\"picked\" value=\"-1\"></form>", basePage.BuildEmoticonGrid(moods, callback, suffix, false)); var content = JSONHelper.ConvertToJSONAssociativeArray( new Dictionary <string, string> { { "fbml", fbml }, { "publishEnabled", "true" }, { "commentEnabled", "true" } }); var data = JSONHelper.ConvertToJSONAssociativeArray( new Dictionary <string, string> { { "content", content }, { "method", "publisher_getInterface" } }); json = data; } else { throw new Exception("no smile picked"); } }
private int RegisterCustomTags(IEnumerable <CustomTag> tags, bool isAsync, RegisterCustomTagsCallback callback, Object state) { var parameterList = new Dictionary <string, string> { { "method", "facebook.fbml.registerCustomTags" } }; var list = new List <string>(); foreach (var item in tags) { var dict = new Dictionary <string, string> { { "name", item.Name }, { "type", item.Type }, { "is_public", item.IsPublic.ToString() }, { "description", item.Description }, { "fbml", item.FBML }, { "open_tag_fbml", item.OpenTagFBML }, { "close_tag_fbml", item.CloseTagFBML }, { "header_fbml", item.HeaderFBML }, { "footer_fbml", item.FooterFBML } //{"label", tag.name}, //{"type", tag.type.ToString(CultureInfo.InvariantCulture)}, //{"description", tag.description}, //{"fbml", tag.body}, //{"open_tag", tag.open_tag}, //{"close_tag", tag.close_tag}, }; var attribList = new List <string>(); foreach (var attrib in item.Attributes) { var dict2 = new Dictionary <string, string> { { "default_value", attrib.DefaultValue }, { "description", attrib.Description }, { "name", attrib.Name } }; attribList.Add(JSONHelper.ConvertToJSONAssociativeArray(dict2)); } dict.Add("attributes", JSONHelper.ConvertToJSONArray(attribList)); list.Add(JSONHelper.ConvertToJSONAssociativeArray(dict)); } Utilities.AddJSONArray(parameterList, "tags", list); //parameterList.Add("tags", JSONHelper.ConvertToJSONArray(itemList)); if (isAsync) { SendRequestAsync <fbml_registerCustomTags_response, int>(parameterList, new FacebookCallCompleted <int>(callback), state); return(0); } var response = SendRequest <fbml_registerCustomTags_response>(parameterList); return(response == null ? 0 : response.TypedValue); }
private string TemplateImagesGen(string imgPath, string URL) { List <string> jsonPaths = new List <string>(); Dictionary <string, string> path = new Dictionary <string, string>(); imgPath = LIB.Util.ApplicationRootPath() + imgPath; //imgPath = "http://www.hayatidoldur.com/Image.ashx?t=1&p=HayatiDoldur_00034_01_300909-133808,1.jpeg&sz=1"; //Test Images path.Add("src", imgPath); path.Add("href", URL); path.Add("target", "_blank"); jsonPaths.Add(JSONHelper.ConvertToJSONAssociativeArray(path)); return(JSONHelper.ConvertToJSONArray(jsonPaths)); }
private bool SetInfo(string title, int type, List <info_field> info_fields, long uid, bool isAsync, SetInfoCallback callback, Object state) { var parameterList = new Dictionary <string, string> { { "method", "facebook.profile.setInfo" } }; Utilities.AddRequiredParameter(parameterList, "title", title); Utilities.AddRequiredParameter(parameterList, "type", type); var fieldList = new List <string>(); foreach (var field in info_fields) { var itemList = new List <string>(); foreach (var item in field.items.info_item) { var itemDict = new Dictionary <string, string> { { "label", item.label }, { "sublabel", item.sublabel }, { "link", item.link }, { "image", item.image }, { "description", item.description } }; itemList.Add(JSONHelper.ConvertToJSONAssociativeArray(itemDict)); } var fieldDict = new Dictionary <string, string> { { "field", field.field }, { "items", JSONHelper.ConvertToJSONArray(itemList) } }; fieldList.Add(JSONHelper.ConvertToJSONAssociativeArray(fieldDict)); } Utilities.AddJSONArray(parameterList, "info_fields", fieldList); Utilities.AddRequiredParameter(parameterList, "uid", uid); if (isAsync) { SendRequestAsync <profile_setInfo_response, bool>(parameterList, !string.IsNullOrEmpty(Session.SessionKey), new FacebookCallCompleted <bool>(callback), state); return(true); } var response = SendRequest <profile_setInfo_response>(parameterList, !string.IsNullOrEmpty(Session.SessionKey)); return(response == null ? false : response.TypedValue); }
protected void Page_Load(object sender, EventArgs e) { if (!string.IsNullOrEmpty(Request.Params["picked"])) { var picked = int.Parse(Request.Params["picked"]); var basePage = new BasePage(); var moods = basePage.getMoods(); var canvas = string.Format("http://apps.facebook.com/{0}/mysmiles.apsx", suffix); var moodList = JSONHelper.ConvertFromJSONArray(this.Api.Data.GetUserPreference(0)); moodList.Insert(0, picked.ToString()); this.Api.Data.SetUserPreference(0, JSONHelper.ConvertToJSONArray(moodList)); var oldCount = 0; if (!string.IsNullOrEmpty(this.Api.Data.GetUserPreference(2))) { oldCount = int.Parse(this.Api.Data.GetUserPreference(2)); } this.Api.Data.SetUserPreference(2, (oldCount + 1).ToString()); var image = string.Format("{0}images/smile{1}.jpg", callback, picked); var images = JSONHelper.ConvertToJSONAssociativeArray(new Dictionary <string, string> { { "src", image }, { "href", canvas } }); var templateData = JSONHelper.ConvertToJSONAssociativeArray( new Dictionary <string, string> { { "mood", moods.ElementAt(picked).Value }, { "emote", moods.ElementAt(picked).Key }, { "images", images }, { "mood_src", image } }); var feed = JSONHelper.ConvertToJSONAssociativeArray( new Dictionary <string, string> { { "template_id", basePage.FeedTemplate1.ToString() }, { "template_data", templateData } }); var content = JSONHelper.ConvertToJSONAssociativeArray( new Dictionary <string, string> { { "feed", feed }, { "next", canvas } }); var data = JSONHelper.ConvertToJSONAssociativeArray( new Dictionary <string, string> { { "method", "feedStory" }, { "content", content } }); json = data; } else { throw new Exception("no smile picked"); } }
private bool SetRestrictionInfo(Dictionary <string, string> restrictionDictionary, bool isAsync, SetRestrictionInfoCallback callback, Object state) { string restriction = JSONHelper.ConvertToJSONAssociativeArray(restrictionDictionary); var parameterList = new Dictionary <string, string> { { "method", "facebook.admin.setRestrictionInfo" } }; Utilities.AddOptionalParameter(parameterList, "restriction_str", restriction); if (isAsync) { SendRequestAsync <admin_setRestrictionInfo_response, bool>(parameterList, !string.IsNullOrEmpty(Session.SessionKey), new FacebookCallCompleted <bool>(callback), state); return(true); } var response = SendRequest <admin_setRestrictionInfo_response>(parameterList, !string.IsNullOrEmpty(Session.SessionKey)); return(response == null ? true : response.TypedValue); }
///// <summary> ///// Configures an application info section that the specified user can install on the Info tab of her profile. ///// </summary> ///// <param name="title">The title or header of the application info section. </param> ///// <param name="type">Specify 1 for a text-only field-item configuration or 5 for a thumbnail configuration.</param> ///// <param name="info_fields">A JSON-encoded array of elements comprising an application info section, including the field (the title of the field) and an array of info_item objects (each object has a label and a link, and optionally contains image, description, and sublabel fields. </param> ///// <param name="uid">The user ID of the user adding the application info section. </param> ///// <returns></returns> public bool setInfo(string title, int type, List <info_field> info_fields, long uid) { var parameterList = new Dictionary <string, string> { { "method", "facebook.profile.setInfo" } }; _api.AddRequiredParameter(parameterList, "title", title); _api.AddRequiredParameter(parameterList, "type", type); var fieldList = new List <string>(); foreach (var field in info_fields) { var itemList = new List <string>(); foreach (var item in field.items.info_item) { var itemDict = new Dictionary <string, string> { { "label", item.label }, { "sublabel", item.sublabel }, { "link", item.link }, { "image", item.image }, { "description", item.description } }; itemList.Add(JSONHelper.ConvertToJSONAssociativeArray(itemDict)); } var fieldDict = new Dictionary <string, string> { { "field", field.field }, { "items", JSONHelper.ConvertToJSONArray(itemList) } }; fieldList.Add(JSONHelper.ConvertToJSONAssociativeArray(fieldDict)); } _api.AddJSONArray(parameterList, "info_fields", fieldList); _api.AddRequiredParameter(parameterList, "uid", uid); var response = _api.SendRequest(parameterList); return(!string.IsNullOrEmpty(response) ? profile_setInfo_response.Parse(response).TypedValue : false); }
private IList <string> RegisterUsers(ICollection <ConnectAccountMap> accountMaps, bool isAsync, RegisterUsersCallback callback, Object state) { var parameterList = new Dictionary <string, string> { { "method", "facebook.connect.registerUsers" } }; var itemList = new List <string>(); foreach (var accountMap in accountMaps) { var mappingDictionary = new Dictionary <string, string>(); // Compute the email_hash mappingDictionary.Add("email_hash", Utilities.GenerateEmailHash(accountMap.EmailAddress)); // If populated set AccountId if (!string.IsNullOrEmpty(accountMap.AccountId)) { mappingDictionary.Add("account_id", accountMap.AccountId); } // If populated set AccountUrl if (!string.IsNullOrEmpty(accountMap.AccountUrl)) { mappingDictionary.Add("account_url", accountMap.AccountUrl); } itemList.Add(JSONHelper.ConvertToJSONAssociativeArray(mappingDictionary)); } Utilities.AddRequiredParameter(parameterList, "accounts", JSONHelper.ConvertToJSONArray(itemList)); if (isAsync) { SendRequestAsync <connect_registerUsers_response, IList <string> >(parameterList, !string.IsNullOrEmpty(Session.SessionKey), new FacebookCallCompleted <IList <string> >(callback), state); return(null); } var response = SendRequest <connect_registerUsers_response>(parameterList, !string.IsNullOrEmpty(Session.SessionKey)); return(response.connect_registerUsers_response_elt); }
/// <summary> /// /// </summary> /// <returns></returns> public string publish(string message, attachment attachment, IList <action_link> action_links, string target_id, int uid) { var parameterList = new Dictionary <string, string> { { "method", "facebook.stream.publish" } }; _api.AddOptionalParameter(parameterList, "message", message); if (attachment != null) { var mediaList = new List <string>(); var cat = new Dictionary <string, string> { { "text", attachment.properties.category.text }, { "href", attachment.properties.category.href } }; var prop = new Dictionary <string, string> { { "category", JSONHelper.ConvertToJSONAssociativeArray(cat) }, { "ratings", attachment.properties.ratings } }; 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 } }; _api.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)); } _api.AddJSONArray(parameterList, "action_links", list); } _api.AddOptionalParameter(parameterList, "target_id", target_id); _api.AddOptionalParameter(parameterList, "uid", uid); var response = _api.SendRequest(parameterList, uid <= 0); return(!string.IsNullOrEmpty(response) ? stream_publish_response.Parse(response).TypedValue : null); }