This project has moved. For the latest updates, please go here.

401 Unauthorized w/ Latest Rev

Sep 17, 2009 at 1:34 PM

I am testing out the web demo to post updates

When signing in with oAuth I have no problems querying my twitter info etc etc however when I go to post

an update whether it be DM or normal update I get

 The remote server returned an error: (401) Unauthorized.

This don't make any sense..... I logged in fine and can query so why the heck can't I post

I am testing things locally could this be the issue? My app settings on twitter is set to read/write so not sure what the deal is.

PS I also have tested this in my actual MVC site and have the same results.

Sep 18, 2009 at 12:30 PM

Try again.  Recently Twitter has been experiencing bugs in their OAuth API.  But they claim it's fixed now:

Sep 18, 2009 at 12:53 PM

Nope apparently it's either still broken or for some reason it doesn't think it's authorized.

Oct 2, 2009 at 4:02 AM

Could someone look into this, I am stil lgetting 401 not authorized when using oAuth, can login and get updates but can not post

My application is setup to do read/write on twitter so not sure what the deal is .. am I the only one with this issue or what?

Oct 10, 2009 at 5:25 PM

Hello!! I keep asking if someone could fix this it appears to be a problem within DotNetOpenAuth... PLEASE RESPOND


Server Error in '/LinqToTwitterWebFormsDemo' Application.

The remote server returned an error: (401) Unauthorized.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Net.WebException: The remote server returned an error: (401) Unauthorized.

Source Error:

Line 223:        {
Line 224:            ((HttpWebRequest)WebRequest.Create(requestUrl)).ServicePoint.Expect100Continue = false;
Line 225:            return (HttpWebResponse)this.Consumer.PrepareAuthorizedRequest(new MessageReceivingEndpoint(requestUrl, HttpDeliveryMethods.PostRequest), this.AccessToken).GetResponse();
Line 226:        }
Line 227:

Source File: D:\Documents\Development\LinqToTwitter_v2.0.1\LinqToTwitter\OAuthAuthorization.cs    Line: 225

Stack Trace:

[WebException: The remote server returned an error: (401) Unauthorized.]
   System.Net.HttpWebRequest.GetResponse() +5373789
   LinqToTwitter.OAuthAuthorization.Post(Uri requestUrl, IDictionary`2 args) in D:\Documents\Development\LinqToTwitter_v2.0.1\LinqToTwitter\OAuthAuthorization.cs:225
   LinqToTwitter.TwitterExecute.ExecuteTwitter(String url, Dictionary`2 parameters, IRequestProcessor requestProcessor) in D:\Documents\Development\LinqToTwitter_v2.0.1\LinqToTwitter\TwitterExecute.cs:390
   LinqToTwitter.TwitterContext.UpdateStatus(String status, String inReplyToStatusID) in D:\Documents\Development\LinqToTwitter_v2.0.1\LinqToTwitter\TwitterContext.cs:613
   LinqToTwitter.TwitterContext.UpdateStatus(String status) in D:\Documents\Development\LinqToTwitter_v2.0.1\LinqToTwitter\TwitterContext.cs:588
   _Default.postUpdateButton_Click(Object sender, EventArgs e) in d:\Documents\Development\LinqToTwitter_v2.0.1\LinqToTwitterWebFormsDemo\Default.aspx.cs:98
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565

Version Information: Microsoft .NET Framework Version:2.0.50727.4927; ASP.NET Version:2.0.50727.4927

<!-- [WebException]: The remote server returned an error: (401) Unauthorized. at System.Net.HttpWebRequest.GetResponse() at LinqToTwitter.OAuthAuthorization.Post(Uri requestUrl, IDictionary`2 args) in D:\Documents\Development\LinqToTwitter_v2.0.1\LinqToTwitter\OAuthAuthorization.cs:line 225 at LinqToTwitter.TwitterExecute.ExecuteTwitter(String url, Dictionary`2 parameters, IRequestProcessor requestProcessor) in D:\Documents\Development\LinqToTwitter_v2.0.1\LinqToTwitter\TwitterExecute.cs:line 390 at LinqToTwitter.TwitterContext.UpdateStatus(String status, String inReplyToStatusID) in D:\Documents\Development\LinqToTwitter_v2.0.1\LinqToTwitter\TwitterContext.cs:line 613 at LinqToTwitter.TwitterContext.UpdateStatus(String status) in D:\Documents\Development\LinqToTwitter_v2.0.1\LinqToTwitter\TwitterContext.cs:line 588 at _Default.postUpdateButton_Click(Object sender, EventArgs e) in d:\Documents\Development\LinqToTwitter_v2.0.1\LinqToTwitterWebFormsDemo\Default.aspx.cs:line 98 at System.Web.UI.WebControls.Button.OnClick(EventArgs e) at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) [HttpUnhandledException]: Exception of type 'System.Web.HttpUnhandledException' was thrown. at System.Web.UI.Page.HandleError(Exception e) at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) at System.Web.UI.Page.ProcessRequest() at System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) at System.Web.UI.Page.ProcessRequest(HttpContext context) at ASP.default_aspx.ProcessRequest(HttpContext context) in c:\Users\Dan\AppData\Local\Temp\Temporary ASP.NET Files\linqtotwitterwebformsdemo\bbda6ee6\43b87231\App_Web_b-id13j2.2.cs:line 0 at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) -->
Oct 11, 2009 at 1:46 PM

Sorry for the late reply.  I work on several open source projects (all volunteer, remember) as well as my day job and get busy at times.

Yes, it looks like you're the only one seeing this issue. I don't know why.  You've mentioned in your messages all the places I would have said to check.  But I just pulled the latest source code and set up my consumer key and secret in the .config file. It authorized, read my private tweets and posted just fine.  I know many others are using the library and haven't reported a problem like yours.  I don't know what to suggest.

Oct 11, 2009 at 2:27 PM

Hi aarnot,

I am getting the same problem, exactly at the same place , 

Oct 11, 2009 at 2:45 PM
Edited Oct 11, 2009 at 4:01 PM

Thanks aarnot.

dswatik, I ran the Web example code again too and it worked fine.  I've also done extensive testing recently, which checks out okay.

Are you seeing the same problem with the examples in Program.cs?  Do username/password updates work fine for you?

Here are some ideas:

- Make sure your application is set to read/write with Twitter. You mentioned that it was, but maybe do an edit and force an update on read/write.

- If that doesn't work, generate a new set of keys.

- If that doesn't work, create a new Twitter application and use they new keys.


Oct 11, 2009 at 2:57 PM

dswatik and Laith,

I'm brainstorming ideas, trying to figure out how to reproduce the problem - What are your locales?  Mine is "en-US".


Oct 11, 2009 at 3:19 PM

Hi Joe,

Mine is en-US too, I recreated my Key and secret as you suggested, I am using this on Azure platform but my testing is local.

the request fail unauthorized at GetResponse() part of IDictionary<string, string> ValidateLogin() , which is very weird, because everything till that point work well, , in general the response is pretty much fine till that point,


one issue though I created a class that inherit from  IConsumerTokenManager to be used in my app other than the one you supplied, any chance the error lay there?

I can email it to you for review


Oct 11, 2009 at 4:19 PM

Apparently everything works except when I update. I am able to login, and able to do anything else except update.

It is really strange....this happens in both examples and I am en-US as well...

When I step through where it is having the problem I am presented with there is no source dialog so I did the disassembly and here it is, as you can see it is coming from DotNetOpenAuth

--- c:\BuildAgent\work\3eacbff3aad45e05\src\DotNetOpenAuth\Messaging\MessageReceivingEndpoint.cs

00000000 push ebp

00000001 mov ebp,esp

00000003 sub esp,18h

00000006 mov dword ptr [ebp-8],ecx

00000009 mov dword ptr [ebp-0Ch],edx

0000000c cmp dword ptr ds:[044E5C74h],0

00000013 je 0000001A

00000015 call 6E8E8F91

0000001a mov ecx,dword ptr [ebp-8]

0000001d call 6DD11438

00000022 mov edx,dword ptr ds:[032726C4h]

00000028 mov ecx,dword ptr [ebp-0Ch]

0000002b call dword ptr ds:[050C358Ch]

00000031 cmp dword ptr [ebp+8],0

00000035 setne cl

00000038 movzx ecx,cl

0000003b mov edx,dword ptr ds:[032726C8h]

00000041 call dword ptr ds:[050C355Ch]

00000047 test dword ptr [ebp+8],6

0000004e setne al

00000051 movzx eax,al

00000054 mov dword ptr [ebp-4],eax

00000057 mov eax,dword ptr ds:[032726C8h]

0000005d mov dword ptr [ebp-10h],eax

00000060 call dword ptr ds:[050C36E0h]

00000066 mov dword ptr [ebp-14h],eax

00000069 xor edx,edx

0000006b mov ecx,72BC3B56h

00000070 call FB11FDA8

00000075 mov dword ptr [ebp-18h],eax

00000078 push dword ptr [ebp-14h]

0000007b push dword ptr [ebp-18h]

0000007e mov edx,dword ptr [ebp-10h]

00000081 mov ecx,dword ptr [ebp-4]

00000084 call dword ptr ds:[050C3568h]

0000008a mov edx,dword ptr [ebp-0Ch]

0000008d mov ecx,dword ptr [ebp-8]

00000090 call dword ptr ds:[050C2B34h]

00000096 mov edx,dword ptr [ebp+8]

00000099 mov ecx,dword ptr [ebp-8]

0000009c call dword ptr ds:[050C2B4Ch]

000000a2 nop

000000a3 mov esp,ebp

000000a5 pop ebp

000000a6 ret 4

Oct 11, 2009 at 4:54 PM


Your code looks very much like the InMemoryTokenManager, except that you're caching tokens, which shouldn't be a problem.  I've tried a few things, like putting in a bad token, but that causes the 401 error before I even get started. 

Have you tried clearing your access token from cache to get Twitter to send it back again?

Does the same problem occur for you with the examples in Program.cs and the Web Demo?


You say that Update is the only thing you can't do.  Are you able to implement other side-effect methods (i.e. Destroy, Block, etc; anything that would cause an HTTP Post)?


Oct 11, 2009 at 5:12 PM


Apparently I can't do anything that requires a post.... that goes through this method

public HttpWebResponse Post(Uri requestUrl, IDictionary<string, string> args)
            ((HttpWebRequest)WebRequest.Create(requestUrl)).ServicePoint.Expect100Continue = false;
            return (HttpWebResponse)this.Consumer.PrepareAuthorizedRequest(new MessageReceivingEndpoint(requestUrl, HttpDeliveryMethods.PostRequest), this.AccessToken).GetResponse();


Oct 11, 2009 at 5:33 PM

Laith & dswatik,

Would you guys mind running fiddler (or whatever HTTP monitoring tool you might use) and send me the raw request and response that occurs in the Post method?


Oct 11, 2009 at 7:20 PM

I've pretty much tried everything I could to reproduce the problem.  FYI the 401 message is coming from Twitter and LINQ to Twitter is informing you of the response that it received from Twitter.  Here's the meaning of the 401 from the Twitter API:

"401 Not Authorized: Authentication credentials were missing or incorrect."

This is why I was asking all the questions about your application settings and keys.  If anyone has an idea of how to reproduce the problem on my system, let me know.


Oct 12, 2009 at 1:15 PM

Hey gang,

Having your own IConsumerTokenManager implementation is totally expected, but that's probably the highest suspect code at the moment.  Both of you: Do the samples work out of the box without any modification other than setting the consumer key and secret?  It sounds like you've tried and they don't, I just want to make sure.

Now, to diagnose the problem, I suggest you turn on logging.  Set it to the most verbose level, and send the entire output (from starting the app to getting the 401).  If there's a problem with your IConsumerTokenManager (or any other problem), I think it should be revealed in the log.

Oct 26, 2009 at 2:42 AM
Edited Oct 26, 2009 at 2:49 AM

@Laith & dswatik: can you guys please do the following for us, including posting some screen shot images (details below)

  • goto
  • login to your account

From here, you should be at your HOME PAGE, that lists all the tweets from you and the people you are following.


  • Click on Connections
  • Take a screenshot and cover up any private information.
  • Upload that screenshot to a public website and post the link in here.

here's an example of my account.
Linq to Twitter Help

What i noticed was that i originally set my application to default to READ only. not READ and WRITE (the picture above shows both read and write, which is correct, now). So when I first grabbed my Access Token, it must have been for a 'read only' application. This is why you could get the public timeline (no authentication required) and your own timeline (read access to your own account).

EDIT: And later on, I checked that the application was defaulting to READ only, so I changed it. BUT, this is where the problem arose! I already had been issued an AccessToken, and that token was for Read only. So even though I updated my application settings in Twitter, that doesn't mean it effects previously generated Access Tokens. So I had to REVOKE that access token and the re-authorise with Twitter again.

Now, if you only have read authentication, then when you try to do a Status Update (ie. a post) then you will get a 401 UNAUTHORISED ERROR. At least, this is what I think i've had/been having with another collegue and I. She was tearing her hair out until we both decided to go back to basics and start all over and check _everything_ out again.

Question: What happens if the application you have setup says READ ACCESS only?

  • goto
  • login to your account
  • now goto
  • click on the application (you have made) that is listed there. If there are none, then make one. (But there should be at least one, otherwise you would never have asked this question OR you've logged in with the wrong account :P )
  • Click on the Edit Application Settings (refer to screenie below)
  • Scroll down and make sure the option Default Access Type: Read & Write is ticked as the default option. (refer to screenie below)

Linq to Twitter Help 2

Linq to Twitter 3


... and then make sure you REVOKE any existing Access Tokens which you might have already authorised for/against.

Hope this helps :)

Oct 26, 2009 at 2:50 AM

Ah ha!! yes that is what the problem is I just looked at my connections and sure enough they say read only.. well that explains it... doh now I feel stupid that I didn't see that.

Oct 26, 2009 at 3:00 AM
thanks a lot, I worked on a simpler way, I created a class for only
oAuth , posted it on my blog , let me know what
you think about it.

either way you were so helpful, thanks a lot

On Sun, Oct 25, 2009 at 10:50 PM, dswatik <> wrote:
> From: dswatik
> Ah ha!! yes that is what the problem is I just looked at my connections and
> sure enough they say read only.. well that explains it... doh now I feel
> stupid that I didn't see that.
> Read the full discussion online.
> To add a post to this discussion, reply to this email
> ([email removed])
> To start a new discussion for this project, email
> [email removed]
> You are receiving this email because you subscribed to this discussion on
> CodePlex. You can unsubscribe on
> Please note: Images and attachments will be removed from emails. Any posts
> to this discussion will also be available online at
Oct 26, 2009 at 3:21 AM

Pleasure folks!