This project has moved and is read-only. For the latest updates, please go here.

Issue with Retweets

Sep 17, 2013 at 5:01 PM
I am using Linq2Twitter in a Windows Phone 8 app.

I am trying to make a Retweet using the following code:
                            response =>

                                if (response == null || response.Status != TwitterErrorStatus.Success)
                                    // do  something
                                    // do something else
Where tweetId is the ID of the tweet I am trying to retweet, and twitterCtx is a TwitterContext object.

The exception is:
base = {System.InvalidOperationException: The JsonData instance has to be initialized first
at LitJson.JsonData.EnsureCollection()
at LitJson.JsonData.get_Count()
at LinqToTwitter.TwitterExecute.ConstructTwitterQueryException(String responseStr, WebExc.....

The exception message is:
Message = "The JsonData instance has to be initialized first"

The first time I try to retweet, it works great, but the second time (obviously can't retweet more than once) it throws an exception and I have no idea where and how to catch it - it crashes my app.

I suppose I should be able to catch it somehow. Can you give me a hint?

Sep 20, 2013 at 10:40 PM

You can't retweet twice. If you want to remove a retweet, you'll have to delete the retweeted tweet. Here's an earlier post where I explain how because it's somewhat tricky. I had a sample at one time, but lost track of where it is, but hopefully the explanation will help.

Sep 23, 2013 at 12:22 PM
Edited Sep 23, 2013 at 12:22 PM
Hi Joe, thanks for the response.

I have another issue with retweets, in particular with this type of call:
(from tweet in twitterCtx.Status
         where tweet.Type == StatusType.Retweets &&
         tweet.StatusID == statusID
         select tweet).MaterializedAsyncCallback(resp =>
where statusID is the ID of a status which has a RetweetCount larger than 0. For example, for my tweet which has been retweeted once:

the StatusID which I'm using is 381502447186739201.

So, I am obviously doing the call right, but I am getting the exception: The remote server returned an error: NotFound.

This is the part of the documentation where I found the example how to do the call

and I have even tried making a request using the matching Twitter API call using a REST console and it gave me the right response and tweets.

Any idea why it's not working for me in LinqToTwitter? Thanks for your time!
Sep 23, 2013 at 4:17 PM
The Not Found response means that Twitter didn't recognize the request or it couldn't find what you were looking for. I just ran that query and received a response. Is it possible that the tweet was not retweeted at the time you did your query? Check for spaces in the StatusID too. Also, make sure you're on the latest version of LINQ to Twitter - 2.1.08.

Sep 24, 2013 at 9:52 AM
To test further, I tried the same code in a simple Console application, and got this exception:

Rate limit exceeded

which was more useful to me. Seems that we've got only 15 retweets API calls... What a shame.

Not sure why the same exception is not showing up in WP8 app, but maybe this will help someone else.

Thanks Joe!
Sep 24, 2013 at 4:49 PM
Rate limits are for a block of 15 minutes. You can use a Help/RateLimits query to see what your limits are for various API calls.