Quantcast
Channel: Tweetinvi a friendly Twitter C# library
Viewing all articles
Browse latest Browse all 4126

New Post: New Programmer / May be running into API Limit

$
0
0
So real quick - I'm writing a console application that reads a list of twitter accounts. Let's say for example you are a video game enthusiast, and you want to follow everyone associated with Unity 3d. So you pull up the Unity 3d list of twitter handles, and auto follow them.

What I don't quite understand is exactly when an API call is used and counted against me in this scenario, so if someone could hold my hand for a minute and tell me how to improve this that would be great.

Right now the app runs, authenticates the user, and follows a fairly decent number of accounts. I'd say it gets 50 at a time. But I haven't necessarily timed it. A few times my program has prematurely printed "press any key..." statement towards the bottom.

How would I put in checks, and read those checks, to debug this? Thanks a bunch for your help.
            // Setup your credentials
            string ConsumerKey = "HIDDEN ON PURPOSE";
            string ConsumerSecret = "HIDDEN ON PURPOSE"
            var ApplicationCredentials = CredentialsCreator.GenerateApplicationCredentials(ConsumerKey, ConsumerSecret);

            // Authorize the app
            var URL = CredentialsCreator.GetAuthorizationURL(ApplicationCredentials);
            ILoggedUser LoggedUser = null;
            while(LoggedUser == null)
            {
                try
                {
                    Process.Start(URL);
                    Console.WriteLine("We directed you to the following address: {0}, so you can authorize"
                    + " our app to access your Twitter Account. Please enter the captcha code provided on the"
                    + " website after loging in:", URL);
                    var Captcha = Console.ReadLine();
                    TwitterCredentials.ApplicationCredentials = CredentialsCreator.GetCredentialsFromVerifierCode(Captcha, ApplicationCredentials);
                    LoggedUser = User.GetLoggedUser(TwitterCredentials.ApplicationCredentials);
                    
                }
                catch (Exception)
                {
                    Console.WriteLine("\r\nWe couldn't log you in. Are you sure you typed the number correctly?"
                        + " Let's try again. Press any key to continue...\r\n");
                    Console.ReadLine();
                }
            }
            Console.WriteLine("\r\nWe successfully logged you in as: {0}\r\n", LoggedUser.Name);


            // Follow a list of accounts
            string[] users = System.IO.File.ReadAllLines(@"c:\twitterHandles.txt");
            if (users.Any())
            {
                foreach(string user in users.Skip(500))
                {
                    var userToFollow = User.GetUserFromScreenName(user);
                    if(userToFollow != null)
                    {
                        if (LoggedUser.FollowUser(userToFollow))
                        {
                            Console.WriteLine("You have successfully sent a request to follow {0}", userToFollow.Name);
                        }
                    }
                }
            }

            Console.WriteLine(@"\r\nThank you for following using our app!\r\nPress any key to quit the program.");
            Console.ReadLine();

Viewing all articles
Browse latest Browse all 4126

Trending Articles