static void StreamInit(TwitterIdCollection friends)
 {
     if (!jsonView)
     {
         Console.WriteLine(string.Format("{0} friends reported.", friends.Count));
     }
 }
예제 #2
0
        public void StartStreaming()
        {
            TwitterIdCollection followingIDs  = null; // TODO: This could update mid-session.. NOTE!!!!111oneone (EventCallback maybe?)
            StreamOptions       streamOptions = new StreamOptions();

            Global.Streaming = new TwitterStream(Global.requestToken, "", streamOptions);
            // override the default Twitterizer user agent, which is "Twitterizer/<version>", because we're assholes :D
            Global.Streaming.GetType().GetField("userAgent", (System.Reflection.BindingFlags) 65535).SetValue(Global.Streaming, "TweetDeck Sucks / 0.01 / [email protected]");

            Global.Streaming.StartUserStream(new InitUserStreamCallback((TwitterIdCollection ee) => {
                followingIDs = ee;
            }), new StreamStoppedCallback((StopReasons stopReason) => {
                Console.WriteLine("StreamStoppedCallback : " + stopReason.ToString());
            }), new StatusCreatedCallback((TwitterStatus tweet) => {
                // if user is following
                if (followingIDs.Contains(tweet.User.Id))
                {
                    // show in timeline columns
                    InsertTweetIn(tweet, ColumnType.Timeline);
                }

                // if user is being mentioned
                if (tweet.Text.ToLower().Contains("@" + Global.ThisUser.ScreenName.ToLower()))
                {
                    // show in mentions columns
                    InsertTweetIn(tweet, ColumnType.Mentions);
                }
            }), new StatusDeletedCallback((TwitterStreamDeletedEvent ee) => {
                foreach (ColumnControl cc in flowColumns.Controls)
                {
                    foreach (TweetControl tc in cc.flowColumn.Controls)
                    {
                        if (tc.Tweet != null && tc.Tweet.Id == ee.Id)
                        {
                            tc.MarkDeleted();
                        }
                    }
                }
            }), new DirectMessageCreatedCallback((TwitterDirectMessage dm) => {
                InsertDMIn(dm, ColumnType.DirectMessages);
            }), new DirectMessageDeletedCallback((TwitterStreamDeletedEvent ee) => {
                foreach (ColumnControl cc in flowColumns.Controls)
                {
                    foreach (TweetControl tc in cc.flowColumn.Controls)
                    {
                        if (tc.DM != null && tc.DM.Id == ee.Id)
                        {
                            tc.MarkDeleted();
                        }
                    }
                }
            }), new EventCallback((TwitterStreamEvent ee) => {
                Console.WriteLine("EventCallback");
            }));
        }
        // Read all followers from an specific user. Suposing the twitter api will return a string, that the kind of object it will send
        public string GetResponse(RepositoryOptions options)
        {
            var twitterIDCollection = new TwitterIdCollection(options.userList.ids);

            var opt = new LookupUsersOptions();
            opt.UserIds = twitterIDCollection;

            var response = TwitterUser.Lookup(GenerateAuthentication(), opt);

            return response.Content;

        }
예제 #4
0
        public void LookupUsersById()
        {
            OAuthTokens tokens = Configuration.GetTokens();

            TwitterIdCollection userIds = new TwitterIdCollection
                                              {
                                                  14725805, // digitallyborn
                                                  16144513, // twit_er_izer
                                                  6253282 // twitterapi
                                              };
            
            var result = TwitterUser.Lookup(tokens, new LookupUsersOptions { UserIds = userIds });

            Assert.IsTrue(result.Result == RequestResult.Success, result.ErrorMessage);
            Assert.IsNotNull(result.ResponseObject, result.ErrorMessage);
        }
        public static void LookupUsersById()
        {
            OAuthTokens tokens = Configuration.GetTokens();

            TwitterIdCollection userIds = new TwitterIdCollection
            {
                14725805,                                 // digitallyborn
                16144513,                                 // twit_er_izer
                6253282                                   // twitterapi
            };

            var result = TwitterUser.Lookup(tokens, new LookupUsersOptions {
                UserIds = userIds
            });

            Assert.That(result.Result == RequestResult.Success);
            Assert.IsNotNull(result.ResponseObject);
        }
예제 #6
0
 private void Init(TwitterIdCollection friends)
 {
 }
 private void Friends(TwitterIdCollection friendids)
 {
 }
 static void StreamInit(TwitterIdCollection friends)
 {
     Console.WriteLine(string.Format("{0} friends reported.", friends.Count));
 }
        public static CommandResult GetRepliedToTweets(decimal[] ids)
        {
            if (!IsInitiated)
            {
                return(CommandResult.NotInitiated);
            }

            Form.AppendLineToOutput(string.Format("Attempt to get tweets which were replied to"), Color.DarkMagenta);

            int numTweets = 0;
            int notAdded  = 0;

            for (int i = 0; i < ids.Length; i += 100)
            {
                TwitterIdCollection idsToLookup = new TwitterIdCollection(ids.Skip(i).Take(100).ToList());

                TwitterContext db = null;
                try
                {
                    TwitterResponse <TwitterStatusCollection> result = null;

                    result = TwitterStatus.Lookup(Tokens, new LookupStatusesOptions
                    {
                        StatusIds = idsToLookup
                    });

                    if (result.Result == RequestResult.Success)
                    {
                        TwitterStatusCollection tweets = result.ResponseObject;

                        //refresh context
                        db = new TwitterContext();
                        db.Configuration.AutoDetectChangesEnabled = false;

                        foreach (TwitterStatus tweet in tweets)
                        {
                            try
                            {
                                numTweets++;

                                TwitterUser userInDb = db.Users.FirstOrDefault(u => u.Id == tweet.User.Id);
                                if (userInDb != null)
                                {
                                    tweet.User = userInDb;
                                }

                                tweet.RetweetedStatus = null;
                                tweet.QuotedStatus    = null;

                                db.Tweets.Add(tweet);
                                db.SaveChanges();
                            }
                            catch (Exception ex)
                            {
                                //Form.AppendLineToOutput(string.Format("{0} -ERROR- {1}", tweet.Id, ex.Message), Color.DarkMagenta);
                                //Form.AppendLineToOutput(ex.StackTrace, Color.DarkMagenta);

                                db        = new TwitterContext();
                                notAdded += 1;
                            }
                        }



                        Form.AppendLineToOutput(string.Format("{0} tweets processed. {1} duplicate {2} not saved.", numTweets, notAdded, notAdded == 1 ? "tweet" : "tweets"), Color.DarkMagenta);
                    }
                    else if (result.Result == RequestResult.RateLimited)
                    {
                        WaitForRateLimitReset(result);

                        Form.AppendLineToOutput("Resuming get replied-to-tweets command", Color.DarkMagenta);
                        continue;
                    }
                }
                catch (Exception e)
                {
                    Exception current = e;
                    Form.AppendLineToOutput(string.Format("Unexpected exception : {0}", e.Message), Color.DarkMagenta);

                    while (current.InnerException != null)
                    {
                        Form.AppendLineToOutput(string.Format("Inner exception : {0}", current.InnerException.Message), Color.DarkMagenta);
                        current = current.InnerException;
                    }

                    db = new TwitterContext();

                    continue; //give up with current batch
                }
                finally
                {
                    if (db != null)
                    {
                        db.Dispose();
                    }
                }
            }

            return(CommandResult.Success);
        }
예제 #10
0
 internal void OnFriends(TwitterIdCollection friendsId)
 {
     if (Friends != null) {
         Friends(friendsId);
     }
 }
 private void Friends(TwitterIdCollection friendids)
 {
 }
예제 #12
0
 private async Task<bool> CheckTwitterNoRetweets()
 {
     if (App.AppState.Accounts[this.TwitterAccountID].IsSignedIn && (this.LastNoRetweetsUpdate <= DateTime.Now.AddHours(-6.0)))
     {
         TwitterResponse<UserIdCollection> asyncVariable0 = await Friendship.NoRetweetIDsAsync(App.AppState.Accounts[this.TwitterAccountID].Tokens, MetroTwitTwitterizer.Options);
         if ((asyncVariable0.Result == RequestResult.Success) && (asyncVariable0.ResponseObject != null))
         {
             this.NoRetweetIds = asyncVariable0.ResponseObject;
             this.LastNoRetweetsUpdate = DateTime.Now;
             this.Save();
         }
     }
     return false;
 }
 /// <summary>
 /// When stream starts pushing content
 /// </summary>
 /// <param name="friends"></param>
 /// <remarks>Example override: string message = string.Format("{0} friends reported.", friends.Count));</remarks>
 public virtual void StreamInit(TwitterIdCollection friends)
 {
     string message = string.Format("{0} friends reported.", friends.Count);
 }
예제 #14
0
 internal void FriendsReceived(TwitterIdCollection friendList)
 {
     this.ResetStopped();
       Messenger.Default.Send<GenericMessage<TwitterIdCollection>>(new GenericMessage<TwitterIdCollection>(friendList), (object) this.MultiAccountifyToken((Enum) ViewModelMessages.StreamingFriends));
       this.retrycount = new int?();
 }