Esempio n. 1
0
        /// <summary>
        /// Simple function that uses ExecuteQuery to retrieve information from the Twitter API
        /// </summary>
        /// <param name="token"></param>
        static void ExecuteQuery(Token token)
        {
            // Retrieving information from Twitter API through Token method ExecuteRequest
            dynamic timeline = token.ExecuteQuery("https://api.twitter.com/1/statuses/home_timeline.json");

            // Working on each different object sent as a response to the Twitter API query
            for (int i = 0; i < timeline.Length; ++i)
            {
                Dictionary<String, object> post = timeline[i];
                Console.WriteLine(String.Format("{0} : {1}\n", i, post["text"]));
            }
        }
Esempio n. 2
0
        public void FillTweet(Token token, bool cleanString = true)
        {
            if (token != null)
            {
                var query = "";
                if (_id != null)
                    query = String.Format(this.query_tweet_from_id_with_entities, id);
                else
                    return;

                // If 404 error throw Exception that Tweet has not been created
                var jsonResponse = token.ExecuteQuery(query);
                dynamic dynamicTweet = jsonResponse;
                if (dynamicTweet is Dictionary<String, object>)
                {
                    Dictionary<String, object> dTweet = dynamicTweet as Dictionary<String, object>;
                    fillTweet(dTweet, cleanString);
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Update the exception handler attribute with the 3rd parameter
        /// Get the list of users matching the Twitter request url (contributors or contributees)
        /// </summary>
        /// <param name="token"> Current user token to access the Twitter API</param>
        /// <param name="url">Twitter requets URL</param>
        /// <param name="exceptionHandlerDelegate">Delegate method to handle Twitter request exceptions</param>
        /// <returns>Null if the token parameter is null or if the Twitter request fails. A list of users otherwise (contributors or contributees).</returns>
        private List<User> getContributionObjects(Token token, String url, Token.WebExceptionHandlingDelegate exceptionHandlerDelegate = null)
        {
            //
            if (token == null)
            {
                Console.WriteLine("User's token is needed");
                return null;
            }

            // Update the exception handler
            //token.Integrated_Exception_Handler = false;
            token.ExceptionHandler = exceptionHandlerDelegate;

            dynamic webRequestResult = token.ExecuteQuery(url);

            List<User> result = null;
            if (webRequestResult != null)
            {
                // Create and fill a user list with the data retrieved from Twitter (Dictionary<String, object>[])
                result = new User[] { }.ToList();
                if (webRequestResult is object[])
                {
                    object[] retrievedContributors = webRequestResult as object[];
                    foreach (object rc in retrievedContributors)
                    {
                        if (rc is Dictionary<String, object>)
                        {
                            Dictionary<String, object> userInfo = rc as Dictionary<String, object>;
                            User u = new User();
                            u.fillUser(userInfo);
                            result.Add(u);
                        }
                    }
                }
            }

            return result;
        }
Esempio n. 4
0
        /// <summary>
        /// Fill User basic information retrieving the information thanks to a Token
        /// <param name="token">Token to use to get infos</param>
        public void FillUser(Token token)
        {
            if (token != null)
            {
                var query = "";
                if (_id != null)
                    query = String.Format(this.query_user_from_id, id);
                else
                    if (_screen_name != null)
                        query = String.Format(this.query_user_from_name, screen_name);
                    else
                        return;

                var jsonResponse = token.ExecuteQuery(query);
                dynamic dynamicUser = jsonResponse[0];
                if (dynamicUser is Dictionary<String, object>)
                {
                    Dictionary<String, object> dUser = dynamicUser as Dictionary<String, object>;
                    fillUser(dUser);
                }
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Uses the handler for only one query / work also for cursor queries
        /// </summary>
        /// <param name="token"></param>
        static void execute_query_error_handler(Token token)
        {
            Token.WebExceptionHandlingDelegate del = delegate(WebException wex)
            {
                Console.WriteLine("You received an execute_query_error!");
                Console.WriteLine(wex.Message);
            };

            dynamic timeline = token.ExecuteQuery("https://api.twitter.com/1/users/contributors.json?user_id=700562792", del);
        }
Esempio n. 6
0
        /// <summary>
        /// When assigning an error_handler to a Token think that it will be kept alive 
        /// until you specify it does not exist anymore by specifying :
        /// 
        /// token.Integrated_Exception_Handler = false;
        /// 
        /// You can assign null value if you do not want anything to be performed for you
        /// </summary>
        /// <param name="token"></param>
        static void token_integrated_error_handler(Token token)
        {
            token.ExceptionHandler = delegate(WebException wex)
            {
                Console.WriteLine("You received a Token generated error!");
                Console.WriteLine(wex.Message);
            };

            // Calling a method that does not exist
            dynamic timeline = token.ExecuteQuery("https://api.twitter.com/1/users/contributors.json?user_id=700562792");

            // Reset to basic Handler
            token.Integrated_Exception_Handler = false;
        }
Esempio n. 7
0
        /// <summary>
        /// Initiating auto error handler
        /// You will not receive error information if handled by default error handler
        /// </summary>
        /// <param name="token"></param>
        static void integrated_error_handler(Token token)
        {
            token.Integrated_Exception_Handler = true;

            // Error is not automatically handled

            try
            {
                // Calling a method that does not exist
                dynamic timeline = token.ExecuteQuery("https://api.twitter.com/1/users/contributors.json?user_id=700562792");
            }
            catch (WebException wex)
            {
                Console.WriteLine("An error occured!");
                Console.WriteLine(wex);
            }
        }