Search code examples
c#tweetinvi

posting message on twitter using tweetinvi does not consistently publish the tweet


i have a list of users i need to post a message to on twitter (post a message on our account and then reference these users using @ID), using tweetinvi. currently, this is my code. i am attempting to post a message every 36 seconds to get the maximum amount of tweets possible per day (2400).

    static void Main(string[] args)
    {
        
        allUsers = analytics.getAllUniqueUserID();
       

       
        System.Timers.Timer aTimer = new System.Timers.Timer();
        aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
        
        aTimer.Interval = 36000;
        aTimer.Enabled = true;

        while (true)
        {
            //just to keep console open
        }
    }

with the timed event as follows

private static void OnTimedEvent(object source, ElapsedEventArgs e)
    {

        lastMessaged = analytics.getLastUserIDMessaged() + 1;
        string identifier = allUsers[lastMessaged];
        string message = "Hello";
        
        TwitterAccess.publicTweetToUsers(identifier, message); 
        analytics.writeLastIDToFile(lastMessaged.ToString());
        
        
        
    }

with publicTweetToUsers as follows

public static void publicTweetToUsers(string identifier, string message)
    {
        Auth.SetUserCredentials(key, secret, token, tokenSecret);
        var user = User.GetAuthenticatedUser();

        var tweet = Tweet.PublishTweet(string.Format("{0} {1}",     identifier, message));

    }

Please note that key,secret,token and tokenSecret are assigned values and the account does log in and send tweets, it just doesn't do it consistently, it will send for a certain duration and then stop. What am I doing wrong ?


Solution

  • I am the developer of Tweetinvi.

    As you mentioned the theoretical limit of tweets per day authorised by Twitter is 2400/day divided in chunks of 30 minutes (50 every 30 minutes).

    Though in order to prevent spam on twitter, their server apply undocumented tests to ensure the tweet is a 'legitimate' tweet.

    So before we consider that the problem comes from the Library, lets analyse what Twitter returns and lets attempt to slightly reduce the number of tweets you publish per day.

    1. Increase the timer to 0.5 seconds (1440 tweets/day).
    2. Check the error returned by Twitter (https://github.com/linvi/tweetinvi/wiki/Exception-Handling#per-request-exception-handling)

    In the error you will find 2 useful properties : TwitterExceptionInfos and TwitterDescription. If these 2 properties do not really help you identify the problem please share all the information available in the TwitterException and I will take a closer look at them.

    Have a great weekend!