Example #1
0
        public void Publish(SocialNetwork socialNetwork, string postText, PublishCallback publishCallback)
        {
            switch (socialNetwork)
            {
            case SocialNetwork.Tweeter:
            {
                tweeterPublishManager.PublishTweet(postText, publishCallback);
                break;
            }

            case SocialNetwork.Facebook:
            {
                break;
            }
            }
        }
Example #2
0
 public void PublishTweet(string tweetText, PublishCallback publishCallback)
 {
     try
     {
         Tweet.PublishTweet(tweetText.Trim());
         publishCallback(null);
     }
     catch (ArgumentException ex)
     {
         publishCallback(new Error("TweeterErrorDomain", 1, "You entred invalid text"));
     }
     catch (Tweetinvi.Exceptions.TwitterException ex)
     {
         publishCallback(new Error("TweeterErrorDomain", 2, "Something went wrong"));
     }
     catch (Tweetinvi.Exceptions.TwitterNullCredentialsException ex)
     {
         publishCallback(new Error("TweeterErrorDomain", 3, "You are not logged in to perform this action"));
     }
 }
        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;
        }
 /// <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&lt;attachment_media&gt;(){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);
 }
 /// <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));
 ///     api.Stream.PublishAsync("Publishing to stream with attachment", 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="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, PublishCallback callback, Object state)
 {
     PublishAsync(message, null, null, null, 0, callback, state);
 }