UpdateStatus Returns Null

Dec 6, 2013 at 5:30 PM
When I try and update the status for some users, UpdateStatus returns null? It does not throw an exception? It is working for some users so I know my code is "right" for authorizing the user, etc. So how do I debug this issue when it returns null and throws no exception?

.
.
.
var twitterCtx = new TwitterContext(auth);
var result = twitterCtx.UpdateStatus(msg);

Thanks,
-J
Coordinator
Dec 6, 2013 at 5:39 PM
Hi,

Go to Debug, Exceptions, and check Thrown for Common Language Runtime. If that lets you catch the exception in a try/catch block, post the message and stack trace for any exceptions and inner exceptions you see.

One common gottcha with doing UpdateStatus is that Twitter doesn't allow duplicates. When testing, I append a DateTime.Now to avoid this problem.

Any tips you have on reproducing this will be helpful.

@JoeMayo
Dec 6, 2013 at 5:43 PM
Hey Joe, thanks for the reply. The problem is no exception is being thrown. Here is more of the code. For one user the result is always null. It does not enter the exception handler?

try
        {
            SingleUserAuthorizer auth = new SingleUserAuthorizer()
            {
                Credentials = new InMemoryCredentials()
                {
                    ConsumerKey = consumer_key,
                    ConsumerSecret = consumer_secret,
                    AccessToken = access_token_secret,
                    OAuthToken = access_token
                }
            };

            auth.Authorize();
            var twitterCtx = new TwitterContext(auth);
            var result = twitterCtx.UpdateStatus(msg);

            if (result == null)
            {
                Logger.log("err", Logger.INFO_LOG, "TwitterModule.cs", "Sending tweet failed for some unknown reason?");
                return false;
            }

        }
        catch (Exception ex)
        {
            Logger.log("err", Logger.INFO_LOG, "TwitterModule.cs", "Handling tweet message transcription failed: " + token + " " + ex.Message + " " + 
            ex.StackTrace);
            return false;
        }
Coordinator
Dec 6, 2013 at 5:51 PM
The reason I was interested in setting the Thrown checkbox in Debug/Exceptions was to see if there was an unhandled exception. I've had a couple recent reports of that particular issue, but haven't tracked it down yet.

Does the RawResult on TwitterContext show anything?

Any way you can launch Fiddler and see what the Request/Response looks like? If you post this, delete the Authorization header value from the request so you tokens don't appear.

@JoeMayo on Twitter
Dec 6, 2013 at 6:35 PM
Not sure why it was not hitting the exception handler on our server, but when I stepped through in the debugger, an exception was thrown and the error was because the status messages was too long. Still investigating but my guess is the library is fine.