Exemple #1
0
        private static void create_tweet_with_entities(Token token)
        {
            // This tweet has classic entities
            Tweet tweet1 = new Tweet(127512260116623360, token);

            // This tweet has media entity
            try
            {
                Tweet tweet2 = new Tweet(112652479837110270, token);
            }
            catch (WebException wex)
            {
                Console.WriteLine("Tweet has not been created!");
            }
        }
        public string DeleteTweet(long id)
        {
            var success = Auth.ExecuteOperationWithCredentials(_credentialService.GetUserCredentials(), () =>
            {
                ITweet toDelete = Tweet.GetTweet(id);
                try
                {
                    toDelete.Destroy();
                    return(true);
                }
                catch (Exception)
                {
                    return(false);
                }
            });

            return(success ? "deleted" : "failed to delete");
        }
Exemple #3
0
        public object Clone()
        {
            Tweet clone = new Tweet();
            clone._in_reply_to_user_id_str = _in_reply_to_user_id_str;
            clone._text = _text;
            clone._id_str = _id_str;
            clone._favorited = favorited;
            clone._source = _source;
            clone._created_at = _created_at;
            clone._user = _user;
            clone._retweet_count = _retweet_count;
            clone._retweeted = _retweeted;

            return clone;
        }
Exemple #4
0
        /// <summary>
        /// Method to start a stream from a Token
        /// </summary>
        /// <param name="token">Token to get the credentials to query the stream</param>
        public void StartStream(Token token)
        {
            if (_isRunning)
            {
                throw new OperationCanceledException("You cannot run the stream multiple times");
            }

            #region Variables
            long     todayTicks = DateTime.Now.Ticks;
            DateTime init       = new DateTime(todayTicks - todayTicks % TimeSpan.TicksPerDay + 1);

            state = StreamState.Resume;
            HttpWebRequest webRequest = token.GenerateRequest(new Uri(StreamUrl));
            StreamReader   reader     = init_webRequest(webRequest);

            string jsonTweet;
            int    error_occured = 0;
            #endregion

            while (state != StreamState.Stop)
            {
                try
                {
                    jsonTweet = null;
                    jsonTweet = reader.ReadLine();

                    #region Error Checking
                    if (jsonTweet == null || jsonTweet == "")
                    {
                        if (error_occured == 0)
                        {
                            ++error_occured;
                        }
                        else if (error_occured == 1)
                        {
                            ++error_occured;
                            webRequest.Abort();
                            reader = init_webRequest(webRequest);
                        }
                        else if (error_occured == 2)
                        {
                            ++error_occured;
                            webRequest.Abort();
                            webRequest = token.GenerateRequest(new Uri(StreamUrl));
                            reader     = init_webRequest(webRequest);
                        }
                        else
                        {
                            Console.WriteLine("Twitter API is not accessible");
                            Trace.WriteLine("Twitter API is not accessible");
                            break;
                        }
                    }
                    else if (error_occured != 0)
                    {
                        error_occured = 0;
                    }
                    #endregion
                    Tweet tweet = Tweet.Create(jsonTweet);

                    if (processTweetDelegate != null)
                    {
                        processTweetDelegate(tweet, false);
                    }
                }
                catch (IOException ex)
                {
                    // Verify the implementation of the Exception handler
                    #region IOException Handler
                    if (ex.Message == "Unable to read data from the transport connection: The connection was closed.")
                    {
                        reader = init_webRequest(webRequest);
                    }

                    try
                    {
                        jsonTweet = reader.ReadLine();
                    }
                    catch (IOException ex2)
                    {
                        if (ex2.Message == "Unable to read data from the transport connection: The connection was closed.")
                        {
                            Trace.WriteLine("Streamreader was unable to read from the stream!");
                            if (processTweetDelegate != null)
                            {
                                processTweetDelegate(null, true);
                            }
                            break;
                        }
                    }
                    #endregion
                }
            }

            #region Clean
            webRequest.Abort();
            reader.Dispose();
            state = StreamState.Stop;
            #endregion
        }
Exemple #5
0
        private static void PublishTweet(string message, string url)
        {
            // 117 is a magical tweet length number
            if (message.Length > 117)
            {
                message = string.Format("{0}…", message.Substring(0, 116));
            }

            Log.WriteInfo("Twitter", "Tweeting \"{0}\" - {1}", message, url);

            try
            {
                ITweet tweet = new Tweet(string.Format("{0} {1}", message, url));

                tweet.Publish(TwitterToken);
            }
            catch (Exception e)
            {
                Log.WriteError("Twitter", "EXCEPTION: {0}\n{1}", e.Message, e.StackTrace);
            }
        }
Exemple #6
0
 public static async Task <IOEmbedTweet> GenerateOEmbedTweet(long tweetId)
 {
     return(await Sync.ExecuteTaskAsync(() => Tweet.GenerateOEmbedTweet(tweetId)));
 }
Exemple #7
0
        private static void processTweet(Tweet tweet, bool force = false)
        {
            if (tweet == null && !force)
                return;

            if (stream_list.Count % 125 != 124 && !force)
            {
                Console.WriteLine(tweet.user.name);
                stream_list.Add(tweet);
            }
            else
            {
                Console.WriteLine("Processing data");
                stream_list.Clear();
            }
        }
Exemple #8
0
 public static async Task <bool> DestroyTweet(long tweetId)
 {
     return(await Sync.ExecuteTaskAsync(() => Tweet.DestroyTweet(tweetId)));
 }
Exemple #9
0
 public static async Task <bool> FavoriteTweet(long tweetId)
 {
     return(await Sync.ExecuteTaskAsync(() => Tweet.FavoriteTweet(tweetId)));
 }
Exemple #10
0
 public static async Task <IEnumerable <ITweet> > GetRetweets(long tweetId)
 {
     return(await Sync.ExecuteTaskAsync(() => Tweet.GetRetweets(tweetId)));
 }
Exemple #11
0
 public static async Task <ITweet> PublishRetweet(long tweetId)
 {
     return(await Sync.ExecuteTaskAsync(() => Tweet.PublishRetweet(tweetId)));
 }
Exemple #12
0
 public static async Task <ITweet> PublishTweetInReplyTo(string text, long tweetToReplyToId)
 {
     return(await Sync.ExecuteTaskAsync(() => Tweet.PublishTweetInReplyTo(text, tweetToReplyToId)));
 }
Exemple #13
0
 public static async Task <ITweet> PublishTweetWithVideo(string text, byte[] media)
 {
     return(await Sync.ExecuteTaskAsync(() => Tweet.PublishTweetWithVideo(text, media)));
 }
Exemple #14
0
 // Tweet Controller
 public static async Task <ITweet> PublishTweet(string text, IPublishTweetOptionalParameters parameters = null)
 {
     return(await Sync.ExecuteTaskAsync(() => Tweet.PublishTweet(text, parameters)));
 }