Ejemplo n.º 1
0
        /// <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);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Returns specified daily metrics for your application, given a date range.
        /// </summary>
        /// <returns></returns>
        public IList <metrics> getMetrics(List <string> metrics, DateTime startDate, DateTime endDate, Period period)
        {
            var parameterList = new Dictionary <string, string> {
                { "method", "facebook.admin.getMetrics" }
            };

            _api.AddRequiredParameter(parameterList, "start_time", DateHelper.ConvertDateToDouble(startDate).ToString());
            _api.AddRequiredParameter(parameterList, "end_time", DateHelper.ConvertDateToDouble(endDate).ToString());
            _api.AddRequiredParameter(parameterList, "period", period.ToString("D"));
            _api.AddJSONArray(parameterList, "metrics", metrics);
            var response = _api.SendRequest(parameterList);

            return(!string.IsNullOrEmpty(response) ? admin_getMetrics_response.Parse(response).metrics : null);
        }
Ejemplo n.º 3
0
        ///// <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);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// This method gives another application access to certain API calls on behalf of the application calling it. The application granted access is specified by permissions_apikey. Which methods or namespaces can be called are specified in method_arr.
        /// </summary>
        /// <param name="method_arr">JSON array of methods and/or namespaces for which the access is granted. If this is not specified, access to all allowed methods is granted.</param>
        /// <returns>The method returns a bool value indicating whether the call succeeded or failed. </returns>
        /// <remarks>The only namespace that can be granted access at this time is admin. </remarks>
        public bool grantApiAccess(string apiKeyGrantedAccess, List <string> method_arr)
        {
            var parameterList = new Dictionary <string, string> {
                { "method", "facebook.permissions.grantApiAccess" }
            };

            _api.AddRequiredParameter(parameterList, "permissions_apikey", apiKeyGrantedAccess);
            _api.AddJSONArray(parameterList, "method_arr", method_arr);

            var response = _api.SendRequest(parameterList);

            return(string.IsNullOrEmpty(response) || permissions_grantApiAccess_response.Parse(response).TypedValue);
        }
Ejemplo n.º 5
0
        private string run(List <string> callList, bool isSerial)
        {
            var parameterList = new Dictionary <string, string> {
                { "method", "facebook.batch.run" }
            };

            _api.AddJSONArray(parameterList, "method_feed", callList);
            if (isSerial)
            {
                _api.AddRequiredParameter(parameterList, "serial_only", "1");
            }
            return(_api.SendRequest(parameterList, true));
        }
        /// <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);
        }