LINQ to Twitter FAQ

1. I get a "401 Unauthorized" Exception. How to I figure out the problem?

A 401 Unauthorized message means that the Twitter server is unable to authorize you. There are several causes for this problem and the following checklist should help you work through the problems:
  • Have you added credentials to an authorizer. You can obtain these credentials from your registered Twitter application. You can register a Twitter application at the Twitter developer site at http://dev.twitter.com. The following documentation explains how to add credentials to a LINQ to Twitter authorizer - http://linqtotwitter.codeplex.com/wikipage?title=Learning%20to%20use%20OAuth&referringTitle=Securing%20Your%20Applications
  • Are your credentials entered properly. Check for misspellings and potential copy and paste errors. Something such as a trailing space is a common gottcha. You can double-check your credentials at the Twitter developer site (http://dev.twitter.com), explained in the previous item.
  • Did you assign the right key to the right token. Make sure you didn't accidentally mix up your ConsumerTokenKey and ConsumerTokenSecret. You can verify your credentials at the Twitter developer site (http://dev.twitter.com).
  • Make sure you've entered a Callback URL for your Twitter application at the Twitter developer site (http://dev.twitter.com).
  • Twitter won't let you use http://localhost as your callback URL, so you may want to use http://127.0.0.1 instead.
  • Check your access level at the Twitter developers site (http://dev.twitter.com). Potential settings are Read, Write, and Direct Message.
  • Makes sure your access level at the Twitter developers site (http://dev.twitter.com) is set for both Read and Write if you need it.
  • Ensure your computer time is up-to-date. The Twitter server reads your OAuth signature (LINQ to Twitter prepares for you) and verifies the time used to build the signature. This time comes from your machine. If the time is off, your OAuth signature is considered invalid. Be aware that the Windows Phone emulator time may need to be reset every time the emulator boots up.
  • Has Twitter disabled your credentials? If you post a message on the Twitter forums that exposes your credentials, Twitter will invalidate your credentials to secure your account. You can re-generate credentials at any time.
  • Has Twitter revoked your application's access. If you've violated any Twitter rules, they might disable your application.
  • Ensure you have permission to perform the operation you're attempting. i.e. Some features are in Beta and require permission. Other features, such as XAuth require permission from Twitter to use.
  • Examine the API call you're trying to use and make sure you have permission to perform the action you're trying to perform. Consult the Twitter documentation (linked to from the bottom of each LINQ to Twitter API documentation page) for the latest details of how the API should be used.
  • Are you using ApplicationAuthorizer improperly? ApplicationOnlyAuthorizer only works for operations that don't operate on behalf of a user. e.g. Search works fine, but UpdateStatus doesn't because it tweets on behalf of a user.
  • Are you using ApplicationOnlyAuthorizer on Streams? It doesn't work on streams and you'll need to use a different type of authorizer.
  • If using SingleUserAuthorizer, the mapping between LINQ to Twitter/Twitter API credentials is OAuthToken/AccesssToken and AccessToken/AccessTokenSecret. Alternatively, use the SingleUserInMemoryCredentials and populate TwitterAccessToken and TwitterAccessTokenSecret instead of OAuthToken and AccessToken, respectively.
  • Please remember to sanitize credentials before posting code or HTTP messages in the discussion forums.
  • Tip: The problem could also involve a combination of these problems. So, it's useful to keep working each item until the problem is resolved.

2. I get a "400 Bad Request" WebException. How to I figure out the problem?

A LINQ to Twitter builds all of the HTTP requests for you, so there's only a limited number of scenarios where this error occurs. In Twitter API v1.0, rate limiting errors appeared as 400, but LINQ to Twitter now supports the Twitter API v1.1, which returns 429 Too Many Requests for rate limit errors.

The most likely reason for a 400 Bad Request is that you didn't authenticate your request. Twitter API v1.1, which LINQ to Twitter suports, requires you to authorize each request. That means you need to use OAuth. For information on how to use OAuth with LINQ to Twitter, visit the Securing Your Applications page. The LINQ to Twitter Samples page and the downloadable source code on this site has examples that use OAuth too.

As with most errors from Twitter, a good way to debug the problem is to use Fiddler to view the HTTP response.
  • Please remember to sanitize credentials before posting code or HTTP messages in the discussion forums.

3. Why are ScreenName and/or UserID properties null in the User entity response from Twitter?

The ScreenName and UserID properties are input only, allowing you to see the parameters you provided in your query.
  • For v2.1.x, use the Identifier property, which has the ScreenName and UserID returned from Twitter.
  • For v3.0.x, use the ScreenNameResponse and UserIDResponse properties.

4. How to I page through Status and Search timelines?

I wrote a blog post, Working with Timelines with LINQ to Twitter, that explains how to do this.

Last edited Feb 5 at 3:17 PM by JoeMayo, version 13