Exception calling UpdateStatus: Missing required parameter: status code 170

Jul 19, 2013 at 4:20 PM
Edited Jul 19, 2013 at 4:30 PM
Hi

I'm getting this exception for some of the tweets i'm trying to publish, can't find a reason why.
  • I'm using a SingleUserAuthorizer
  • Linq2twitter 2.1.7
  • I'm doing replies, so I call
string text =  "@username this a reply for you\nthanks. see this link :\n http://goo.gl/xxxx";
twitterCtx.UpdateStatus(text, mention.StatusID);
  • I'm making 100% sure text is not null or empty.
  • Seems to happen randomly. Out of 20 tweets with the same structure, 2 or 3 of them fail with this exception. I have an automatic system that post tweets based on mentions, so it posts about 200-400 tweets a day.
Any ideas?

Thanks!
Coordinator
Jul 19, 2013 at 5:02 PM
Hi,

Not sure - what are the exception details. One thing you might consider is that Twitter doesn't accept duplicate tweets.

@JoeMayo
Coordinator
Jul 19, 2013 at 5:06 PM
Silly me - just looked at your subject line and I see the error. Looking at Twitter's description of statuses/update, I would check to see if the @username is the person who tweeted mention.StatusID.

@JoeMayo
Jul 20, 2013 at 5:03 PM
Edited Jul 20, 2013 at 5:08 PM
Joe
  • No duplicated tweet: for this cases, I got the appropiate exception telling me that
here's a code snippet of what I'm doing:
var myMentions = (from mention in twitterCtx.Search
 where mention.Query=="@myusername"  && mention.SinceID == lastID
 && mention.IncludeEntities == true &&mention.Type == SearchType.Search 
 select mention).SingleOrDefault();

if (myMentions != null)
{
foreach (Status mention in myMentions.Statuses)
{
doTweet(mention);
}
}

public void doTweet(Status mention)
        {
string response = "@" + mention.User.Identifier.ScreenName +"\ntext to send to user lorem ipsum";
var status = twitterCtx.UpdateStatus(text, mention.StatusID);

}
  • Is it possible that mention.StatusID is null?
  • Should I be using a different property to get the id of the tweet I want to reply to?
  • Should I be using a different property to get the @username I reply to?
I keep investigating.

Thanks!
Jul 21, 2013 at 2:04 AM
Exception details

System.Net.WebException
The remote server returned an error: (403) Forbidden.

LinqToTwitter.TwitterQueryException: Missing required parameter: status ---> System.Net.WebException: The remote server returned an error: (403) Forbidden.
at LinqToTwitter.TwitterExecute.PostToTwitter[T](String url, IDictionary2 postData, Func2 getResult)
--- End of inner exception stack trace ---
at LinqToTwitter.TwitterExecute.PostToTwitter[T](String url, IDictionary2 postData, Func2 getResult)
at LinqToTwitter.StatusExtensions.UpdateStatus(TwitterContext ctx, String status, Decimal latitude, Decimal longitude, String placeID, Boolean displayCoordinates, String inReplyToStatusID, Boolean trimUser, Action`1 callback)
at LinqToTwitter.StatusExtensions.UpdateStatus(TwitterContext ctx, String status, String inReplyToStatusID)
at Data.Utilities.TwitterWriter.doTweet(Status mention, TwitterContext twitterCtx)
  • status is not null, and contains the right username
Coordinator
Jul 21, 2013 at 2:57 AM
I still don't know what could be causing this. However, here are some ideas on how to debug the problem.
  1. If you figure out how to reproduce the problem on demand, then run Fiddler and post the request and response here. Remember that when posting HTTP output, you need to obfuscate your secrets. This means that you should remove the values assigned to the Authentication header parameters. That way, you don't accidentally post your credentials on-line.
  2. Do exception handling and capture TwitterQueryException. If the InnerException is WebException, then log the HTTP Status Code, the TwitterQueryException Status code and the TwitterQueryException message. Also, log the DateTime, text and status ID that you're trying to tweet.
  3. Write a simple program that does an UpdateStatus with the text and status ID where you encountered the error and see if it produces an exception every time. If it does, then there's a reproducible scenario. If it doesn't produce an error then it's possible that this represents some type of intermediate error from the Twitter API and you can mitigate the problem by doing a few timed retries any time you encounter this specific error.
  4. Create a class that derives from TextWriter, overrides WriteLine and logs results for you. Assign that class to the Log property (which is type TextWriter) of your TwitterContext instance. The log entry should include the DateTime so that you can correlate it with the DateTime of the exception.
  5. If it's possible to make this happen within a certain timeframe, then hook up Fiddler and watch the traffic. As soon as you get the 403, Fiddler will make the request Red and you can click on it and look at the response from Twitter.
  6. You can also log DateTime, Text, and Status ID for every request, which might help correlate the request with a specific error.
Like I said, these are a few ideas, but hopefully they get you going in the right direction.

@JoeMayo
Jul 22, 2013 at 1:16 AM
Edited Jul 22, 2013 at 1:16 AM
Joe

Thanks for taking the time to review the issue, I really appreciate it.

I was able to do a workaround based on your suggestions:
  • I added exception handling to catch the TwitterQueryException, and retry to do the UpdatStatus immediatly if ErrorCode==170 only.
    On the retry, I used UpdateStatus without the mentionID, so it won't be a reply to an status. It works.
Some thoughts:
  • This is a service that runs every minute, checking for mentions, and replying based on the message. So users expect to have a response on less than 60 seconds (sometimes a few seconds).
Can it be true that, the tweet is so recent, that trying to reply to it will fail? That's my only guess now, will have to write some unit test to confirm. Anyway, seems to be some odd behavoir on twitter API 1.1. (not Linq2Twitter, it rocks!)

Thanks

David
Coordinator
Jul 22, 2013 at 1:24 AM
David,

I think you may be right. Unlike relational/transactional systems, Twitter stores data in an "eventually-consistent" manner. So, it's very possible that you've replied before their system knows about the tweet being replied to. I encountered a similar (but different) situation not too long ago where Twitter API implemented favorite_count on Statuses, the numbers weren't being updated right away, but they would eventually be updated correctly. Thanks for your patience too. :)

@JoeMayo
Coordinator
Jul 23, 2013 at 3:55 AM
I found the problem with this and you'll want to upgrade to the latest version of LINQ to Twitter. I explain what the problem is in LINQ to Twitter v2.1.08 Released.

@JoeMayo
Jul 23, 2013 at 11:01 AM
Edited Jul 23, 2013 at 11:14 AM
Thank Joe. But i get {"errors":[{"message":"Could not authenticate you","code":32}]} when using v2.1.08.
And I figure that the request headers didn't contain Content-Type.
How can i fix it or add Content-Type to the request headers?

Thanks
HungLNG
Jul 23, 2013 at 2:44 PM
Joe.
Yesterday my app stopped working (as several people notified) and every attempt to update an status was retuning that 170 error.
Last night I updated the dll and now it works fine.
Thank you very much!