1

Closed

Error 401. Unauthorized.

description

I am using the LinqToTwitter samples is ASP.NET, in particular the WebFormsTweetsDemo. I have set up my Twitter app, set the access levels to read/write. When I run the sample app, the app authorizes and connects, but when sending the message:-

var tweet = twitterCtx.UpdateStatus(txtUpdateStatus.Text, coordLat, coordLong);

The 401 error is raised. I checked and rechecked the app settings on twitter and even created a second app, but the error keeps occurring.

Can anyone shed some light on this?
Closed Jan 20, 2013 at 12:37 AM by JoeMayo

comments

JoeMayo wrote Dec 19, 2012 at 12:58 AM

Hi Robert,

There are many reasons for 401 errors. I've written a FAQ to cover many of them:

http://linqtotwitter.codeplex.com/wikipage?title=LINQ%20to%20Twitter%20FAQ&referringTitle=Documentation

Joe

JoeMayo wrote Dec 19, 2012 at 12:58 AM

** Closed by JoeMayo 12/18/2012 4:58PM

RobertTisc wrote Dec 19, 2012 at 4:11 AM

Hi Joe, I had already check all of these things. The app I am running is the standard sample app with just the codes modified. I can get authorization, but cannot post.

The only thing that I am unsure of is the callback URL. I don't have one, I am developing the app from my desktop. Is there a particular way I should setup my twitter app for this scenario?

Many thanks,
Robert.

RobertTisc wrote Dec 19, 2012 at 4:17 AM

Hi Joe. I had checked these things many times before posting this message. I can get authorized but cannot post. I am using the standard sample app with nothing other than changing the access codes.

The only thing I am unsure of is the callback URL, I have tried leaving this blank and also tried directing it to my URL's home page, but I am using my desktop to develop the app and not my website. Do I need to get some type of way to enter a URL for my desktop machine? If so, what port should I use?

Many thanks.
Robert.

RobertTisc wrote Dec 19, 2012 at 10:50 AM

Hi Joe,
No I am afraid that I studied that webpage many times and searched the internet high and low but I cannot seem to find any solution.

JoeMayo wrote Dec 19, 2012 at 12:55 PM

I have a samples page at:

http://linqtotwitter.codeplex.com/wikipage?title=LINQ%20to%20Twitter%20Samples&referringTitle=Home

Have you tried any of these? What version of .NET are you using?

There's a known issue with .NET 4.5 Uri class unescaping special characters: "*():'[]". I've updated the source code with some modifications that partially address that. So, you can download the source code and try that too.

Joe

RobertTisc wrote Dec 19, 2012 at 4:08 PM

Yes Joe, these are in fact the sample progams I am using.

RobertTisc wrote Dec 19, 2012 at 7:25 PM

Again, I checked and rechecked these instructions. I still cannot get it to work.

By the way, I am using .Net4.0 and Visual Studio 2010 Service Pack #1

JoeMayo wrote Dec 19, 2012 at 11:41 PM

Can you try the LinqToTwitterDemo project in the downloadable source code?

Joe

RobertTisc wrote Dec 20, 2012 at 12:35 PM

Hi Joe,

I have attempted your suggestion, I cannot get the program to compile. There is obviously some type of version mismatch. The problem when compiling is :-

Error 72 No overload for method 'UpdateList' takes 6 arguments C:\comp2012\VS2010\LinqToTwitter\LinqToTwitterSource_20120514\LinqToTwitterDemo\ListDemos.cs 174 25 LinqToTwitterDemo

JoeMayo wrote Dec 20, 2012 at 1:26 PM

Are you able to get one of the console samples from the Sample page to run?

Joe

RobertTisc wrote Dec 20, 2012 at 2:37 PM

Hi Joe,
I have not tried any console app, I have been working with the WebFormsTweetsDemo. I cannot seem to find where the console app are located. If you can provide a link to this page I would be much obliged.

Robert.

JoeMayo wrote Dec 21, 2012 at 1:09 PM

You can find the samples on the home page of this site. You can find the documentation by clicking the Documentation tab on the menu on this site. You can also read my holiday message on the discissuon forum, which is also a tab on the menu on this site.

You've opened an issue, which is typically reserved for new features and bugs. This is neither, so I'm going to close this issue again.

Joe

JoeMayo wrote Dec 21, 2012 at 1:09 PM

** Closed by JoeMayo 12/21/2012 5:09AM

RobertTisc wrote Dec 24, 2012 at 2:30 PM

Hi Joe,
Thank you, I found the console demos and they work fine. However the ASP.NET demos do not work when writing to Twitter, they are however authorized. Any ideas?

I am fairly new to c# as I am a c++ developer so please excuse the naivety. I was unaware that this site was typically reserved for new feature and bugs, you may well issue a notice to that effect. Where should I post such issues as these?

The bottom line is that using the ASP.NET demos raises a 401 exception. The console app does not.

If you feel that the problem is too elementary for you, let me know and I will find it myself although it would be nice to save a bit of time and quickly find a solution from the experts.

Merry Xmas,
Robert.

JoeMayo wrote Dec 24, 2012 at 7:23 PM

There are different parts of the site for different purposes. This part that you're posting in is for bugs and new features. There's also a Discussions forum, which you can see at the top of the page where the tab says "DISCUSSIONS". People typically use the discussions area for getting help on how to use LINQ to Twitter, which is typical practice among all of the CodePlex sites or similar open-source hosting sites. There isn't a problem with you or anyone else asking questions. However, if everyone posted questions in the ISSUES area, it would make it hard to tell the difference between what is a bug and what is a support request. My recommendation is that the next time you have a question, it would be better to post the question in the discussion forum, unless you really have found a bug and want to report it. The rule of thumb is, use Discussions to ask questions and use Issues to report a software bug.

Now, you've achieved some degree of success in being able to run a console program. This is important to know so we don't end up looking at things that we know already work. Are any of the WebForms demo projects on the Samples page, http://linqtotwitter.codeplex.com/wikipage?title=LINQ%20to%20Twitter%20Samples&referringTitle=Home, working for you? i.e. did you try the WebFormsSearchDemo or the WebFormsOAuthDemo?

Another item is what are you tweeting? Twitter does not allow duplicates. If you have ever tweeted the words "Test" and then tried to tweet "Test" again, you'll get an error.

A tool that I use all the time to debug HTTP traffic is Fiddler (http://fiddler2.com/fiddler2/). This will let you see the real response that Twitter is sending back. Sometimes the error returned from Twitter is not obvious and looking at the HTTP response via Fiddler provides clearer information.

Joe

RobertTisc wrote Dec 27, 2012 at 11:52 AM

Hi Joe,
Hope your having a good xmas. I tried the sample you mentioned and it also works fine. I have done a lot of playing around and it seems that some apps are working where others are not. Any apps that are used to perform a write, or a search are not working. ie-
    "from list in twitterCtx.List" - Works
    "from list in twitterCtx.Lookup" - Broken
This piece of code below will also generare a 401 if I use any other Id that myself (my followers generate 401).
        var user =
            (from usr in twitterCtx.User
             where usr.Type == UserType.Search &&
                   usr.Query == "RobertTisc"
             select usr)
             .FirstOrDefault();
I have installed Fiddler, it is a very useful tool. Although all I can from it is a 401 unauthorized response. If indeed you clueless, I can give you access to my computer.

Thanks for for help.

Robert.