Twitter User/Search Feature Header Support in LINQ to Twitter
- by Joe Mayo
LINQ to Twitter’s goal is to support the entire Twitter API. So, if you see a new feature pop-up, it will be in-queue for inclusion. The same holds for the new X-Feature… response headers for User/Search requests. However, you don’t have to wait for a special property on the TwitterContext to access these headers, you can just use them via the TwitterContext.ResponseHeaders collection. The following code demonstrates how to access the new X-Feature… headers with LINQ to Twitter:
var user =
(from usr in twitterCtx.User
where usr.Type == UserType.Search &&
usr.Query == "Joe Mayo"
select usr)
.FirstOrDefault();
Console.WriteLine(
"X-FeatureRateLimit-Limit: {0}\n" +
"X-FeatureRateLimit-Remaining: {1}\n" +
"X-FeatureRateLimit-Reset: {2}\n" +
"X-FeatureRateLimit-Class: {3}\n",
twitterCtx.ResponseHeaders["X-FeatureRateLimit-Limit"],
twitterCtx.ResponseHeaders["X-FeatureRateLimit-Remaining"],
twitterCtx.ResponseHeaders["X-FeatureRateLimit-Reset"],
twitterCtx.ResponseHeaders["X-FeatureRateLimit-Class"]);
The query above is from the User entity, whose type is Search; allowing you to search for the Twitter user whose name is specified by the Query parameter filter. After materializing the query, with FirstOrDefault, twitterCtx will hold all of the headers, including X-Feature… that Twitter returned. Running the code above will display results similar to the following:
X-FeatureRateLimit-Limit: 60
X-FeatureRateLimit-Remaining: 59
X-FeatureRateLimit-Reset: 1271452177
X-FeatureRateLimit-Class: namesearch
In addition to getting the X-Feature… headers a capability you might have noticed is that the TwitterContext.ResponseHeaders collection will contain any HTTP that Twitter sends back to a query. Therefore, you’ll be able to access new Twitter headers anytime in the future with LINQ to Twitter.
@JoeMayo