Null Exception - Value cannot be null. Parameter name: source

Dec 8, 2014 at 8:24 AM
Edited Dec 8, 2014 at 4:40 PM
Hi there,

I am experiencing some inconsistent behavior when utilizing the library. I am trying to retrieve tweets as so:
private IOAuthCredentials Credentials { get; set; }
        
//class constructor
public Twit()
{
       Credentials = TwitterCredentials.CreateCredentials(
                "...",
                "...",
                "...",
                "..."
       );
}

//function call which throws error
public List<ITweet> SearchInPosts(string query)
{
       List<ITweet> inPosts = new List<ITweet>();

       TwitterCredentials.ExecuteOperationWithCredentials(Credentials, () =>
       {
            var searchParam = Search.GenerateSearchTweetParameter(query);
            searchParam.Lang = Language.English;
            searchParam.MaximumNumberOfResults = 1000;
            searchParam.TweetSearchFilter = TweetSearchFilter.OriginalTweetsOnly;
            inPosts = Search.SearchTweets(searchParam); //ERROR comes from searchParam
       });

       return inPosts;
}
I'm losing my mind trying to solve this problem. I get a proper return the first few tries, then subsequently after that, I encounter this error. It also seems that I have to wait a certain amount of time to have it work again, but that may be my imagination. There also appears to be no attribute for "name" in searchParam, which leads to more confusion on my part.

I have also tried using "SetCredentials" as described in this post, but still no luck.

Am I using the library correctly? Or am I missing something completely?


EDIT This thread has been moved to the "issues" section because it is an issue with the library.
Coordinator
Dec 8, 2014 at 5:28 PM
A fix has already been implemented, you can use it by downloading the Source Code. It will be available as part of Tweetinvi 0.9.4.1.
This problem happens only when an Exception has been throw by Twitter.

It means that you can fix this problem before the patch comes up.

Add a Try/Catch around your code and use the exception handler to understand what is wrong with the code.
I believe the issue here is the fact that you are reaching the RateLimit of Twitter.
TwitterCredentials.ExecuteOperationWithCredentials(Credentials, () =>
{
    var searchParam = Search.GenerateTweetSearchParameter(query);
    searchParam.Lang = Language.English;
    searchParam.MaximumNumberOfResults = 1000;
    searchParam.TweetSearchFilter = TweetSearchFilter.OriginalTweetsOnly;

    try
    {
        inPosts = Search.SearchTweets(searchParam); //ERROR comes from searchParam
    }
    catch (Exception)
    {
        var lastException = ExceptionHandler.GetLastException();
        Console.WriteLine(lastException.ToString());
    }
});
Linvi
Dec 8, 2014 at 7:13 PM
linvi,

Thanks for the response. I ran the query again and yes the exception details "remote server returned an error (429) too many requests". The twitter documentation specifies limits of 180 & 450 for user/app auth, respectively. I am sure I am not clicking my button 180 times or even 450 times within the 15 minutes time window. Are you saying that I may be requesting too many search results in the "MaximumNumberOfResults" attribute?

How might I work around this? My application is intended to find keywords in a vast amount of tweets in order to gauge public opinion on a product.

Thanks,

user1087
Coordinator
Dec 9, 2014 at 5:11 PM
Hi,

Are you saying that I may be requesting too many search results in the "MaximumNumberOfResults" attribute?

Yes you are reaching the rate limits because of the MaximumNumberOfResults.

How might I work around this? My application is intended to find keywords in a vast amount of tweets in order to gauge public opinion on a product.

The FilteredStream is intended to be used for such purpose. The difference with the search is that you cannot get it for past posts, only new ones.
When you have your FilteredStream up and running store the Tweets into a database and return the results when you want these.

If you also want to search for tweets in the past (as I sometimes do), you will need to be careful with the RateLimits.

Please let me know if this makes any sense.
Linvi