[twitter-dev] Re: Desktop App oAuth GET request with valid accesstoken returns 401 Unauthorized
Any Idea out there? I tried following to no avail: a. Did the entire process (starting from registering the app and generating consumer key/secret to getting Access Token/secret. Works fine till I get Access Token & Secret b. When I copy/paste complete URL in browser's address bar, it prompts for credentials saying - "The server twitter.com:80 at Twitter API requires a username and password". Wondering if port 80 is the problem? But I think oAuth documentation states this as default behaviour and I see no documentation on twitter to provide Port number in URL. c. Ran my program with both scenarios – logged in and logged out from the twitter account in a browser. d. Tried with both “/verify_credentials.xml” and “/user_timeline.xml” More notes about the application: 1. .net 3.5/C# 2. Desktop/Console application 3. Using http://oauth.googlecode.com/svn/code/csharp/OAuthBase.cs as the base and extended it to suit desktop/PIN related bits. 4. Stored Access Token and Secret in a text file and copy/pasted in code as a consts (just if this matters. I cross checked the characters). 5. The Twitter account shows application in Setting>Connection and Setting>Connection Browse. I do not think this could be an issue that the account for both is same. 6. Pseudocode (to access protected resources) a. Generate Signature, Request URL and parameter with URI, consumer key, consumer secret, token key and token secret b. Concatenate Request URL, Parameters and Signature to form final URL c. Create HttpWebRequest object with URL d. Set HttpWebRequest object’s method to GET e. Set ServicePoint.Expect100Continue to false f. Set UserAgent g. Timeout 2000 h. Get a new StreamReader from HttpWebRequest.GetResponse ().GetResponseStream i. StreamReader.ReadToEnd (ERROR!) 7. Stack Trace • at System.Net.HttpWebRequest.GetResponse() • at OAuthWalkthroughConsole.WebHelper1.WebResponseGet(HttpWebRequest webRequest) in D:\Development\POC\TwitterPrototype \ConsoleTest2\ConsoleTest2\Program.cs:line 193 • at OAuthWalkthroughConsole.WebHelper1.WebRequest(String method, String url, String postData) in D:\Development\POC\TwitterPrototype \ConsoleTest2\ConsoleTest2\Program.cs:line 168 • at OAuthWalkthroughConsole.Program.Main() in D:\Development\POC \TwitterPrototype\ConsoleTest2\ConsoleTest2\Program.cs:line 40 • at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args) • at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) • at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly () • at System.Threading.ThreadHelper.ThreadStart_Context(Object state) • at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) • at System.Threading.ThreadHelper.ThreadStart() How I wish Twitter returned more detailed errors! I could not make anything of “401 Unauthorized”. Is it wrong token/key or the encoding or the parameters, what? Does Twitter API still have issues giving access to PIN based Token/ Secret from desktop clients? But I see many people got access. Is the behaviour (of getting access through desktop) consistent? What is going wrong here? On Dec 15, 4:48 am, Sanjay wrote: > I got my desktop application registered on Twitter and successfully > got the PIN which I used to generate Token and Secret Key. I am > generating following signature for verify_credentials: > > http://twitter.com/account/verify_credentials.xml?oauth_consumer_key=... > > It always returns 401 Unaushorized error. Am I missing something. The > Response Header below: > > Response Object Header > {Status: 401 Unauthorized > X-Runtime: 0.00163 > Vary: Accept-Encoding > Connection: close > Content-Length: 419 > Cache-Control: no-cache, max-age=1800 > Content-Type: application/xml; charset=utf-8 > Date: Mon, 14 Dec 2009 23:34:46 GMT > Expires: Tue, 15 Dec 2009 00:04:46 GMT > Set-Cookie: > _twitter_sess=BAh7BzoHaWQiJWZhYWE0ZjgwOTY4ZDA5ZDIzMjRjOTVmY2UxMmNlOWM1Igpm > %250AbGFzaElDOidBY3Rpb25Db250cm9sbGVyOjpGbGFzaDo6Rmxhc2hIYXNoewAG > %250AOgpAdXNlZHsA--482b347c66dc8e1643fcf1b99a82f36aeee38f41; > domain=.twitter.com; path=/ > Server: hi > WWW-Authenticate: Basic realm="Twitter API" > > > > }
[twitter-dev] Re: Desktop App oAuth GET request with valid accesstoken returns 401 Unauthorized
We are still trying with no luck :-(. Is somebody from Twitter listening who could help us here? I think we are making some little mistake which is blocking us. It's really frustrating. Maybe if somebody could check at server side and let us know if our encoding or string formation or what might be the issue. Please help!!! Does it matter from which region (country) we are trying to make these calls? I hope not. We are trying this from India. Some more things we tried: 1. We put Authorization in header as below (once with oauth_signature encoded and once without encoded, we get two different error codes, see below for detail): -Header without oauth_signature encoded {User-Agent: Testweet Content-Type: application/x-www-form-urlencoded Authorization: OAuth realm="Twitter API",oauth_consumer_key="--- removed---",oauth_nonce="68f3e3ca5d7440e5bac6cbc08029d817",oauth_signature_method="HMAC- SHA1",oauth_timestamp="1261129193",oauth_token="--- removed---",oauth_version="1.0",oauth_signature="uVAiNwVqoSa8FFqZ/HRN/ rwhod0=" } We get following error: {Status: 500 Internal Server Error Vary: Accept-Encoding Connection: close Content-Length: 4684 Cache-Control: no-cache, max-age=300 Content-Type: text/html; charset=utf-8 Date: Fri, 18 Dec 2009 09:40:27 GMT Expires: Fri, 18 Dec 2009 09:45:27 GMT Set-Cookie: _twitter_sess=xxx; domain=.twitter.com; path=/ Server: hi } -Header with oauth_signature encoded {User-Agent: TestTweet Content-Type: application/x-www-form-urlencoded Authorization: OAuth realm="Twitter API",oauth_consumer_key="--- removed---",oauth_nonce="88b3f32da1fe46c7af8581f63e869c14",oauth_signature_method="HMAC- SHA1",oauth_timestamp="1261129414",oauth_token="--- removed---",oauth_version="1.0",oauth_signature="h %2FHxJ9zS0UWISrh4T2762u5paA0%3D" } We get following error: {Status: 401 Unauthorized Vary: Accept-Encoding Connection: close Content-Length: 148 Cache-Control: no-cache, max-age=1800 Content-Type: application/xml; charset=utf-8 Date: Fri, 18 Dec 2009 09:44:13 GMT Expires: Fri, 18 Dec 2009 10:14:13 GMT Set-Cookie: _twitter_sess=xxx; path=/ Server: hi WWW-Authenticate: Basic realm="Twitter API" } Thank On Dec 15, 6:52 pm, Sanjay wrote: > Any Idea out there? I tried following to no avail: > > a. Did the entire process (starting from registering the app and > generating consumer key/secret to getting Access Token/secret. Works > fine till I get Access Token & Secret > b. When I copy/paste complete URL in browser's address bar, it prompts
[twitter-dev] Re: Desktop App oAuth GET request with valid accesstoken returns 401 Unauthorized
Sanjay, There are several really good .NET libraries that handle OAuth already. I would give TweetSharp a look to see if it meets your needs. You might also want to look at TwitterVB. http://tweetsharp.com http://twittervb.codeplex.com On Dec 18, 5:01 am, Sanjay wrote: > We are still trying with no luck :-(. Is somebody from Twitter > listening who could help us here? I think we are making some little > mistake which is blocking us. It's really frustrating. Maybe if > somebody could check at server side and let us know if our encoding or > string formation or what might be the issue. Please help!!! Does > it matter from which region (country) we are trying to make these > calls? I hope not. We are trying this from India. > > Some more things we tried: > > 1. We put Authorization in header as below (once with oauth_signature > encoded and once without encoded, we get two different error codes, > see below for detail): > > -Header without oauth_signature encoded > {User-Agent: Testweet > Content-Type: application/x-www-form-urlencoded > Authorization: OAuth realm="Twitter API",oauth_consumer_key="--- > removed---",oauth_nonce="68f3e3ca5d7440e5bac6cbc08029d817",oauth_signature_ > method="HMAC- > SHA1",oauth_timestamp="1261129193",oauth_token="--- > removed---",oauth_version="1.0",oauth_signature="uVAiNwVqoSa8FFqZ/HRN/ > rwhod0=" > > } > > We get following error: > > {Status: 500 Internal Server Error > Vary: Accept-Encoding > Connection: close > Content-Length: 4684 > Cache-Control: no-cache, max-age=300 > Content-Type: text/html; charset=utf-8 > Date: Fri, 18 Dec 2009 09:40:27 GMT > Expires: Fri, 18 Dec 2009 09:45:27 GMT > Set-Cookie: _twitter_sess=xxx; domain=.twitter.com; path=/ > Server: hi > > } > > -Header with oauth_signature encoded > > {User-Agent: TestTweet > Content-Type: application/x-www-form-urlencoded > Authorization: OAuth realm="Twitter API",oauth_consumer_key="--- > removed---",oauth_nonce="88b3f32da1fe46c7af8581f63e869c14",oauth_signature_ > method="HMAC- > SHA1",oauth_timestamp="1261129414",oauth_token="--- > removed---",oauth_version="1.0",oauth_signature="h > %2FHxJ9zS0UWISrh4T2762u5paA0%3D" > > } > > We get following error: > > {Status: 401 Unauthorized > Vary: Accept-Encoding > Connection: close > Content-Length: 148 > Cache-Control: no-cache, max-age=1800 > Content-Type: application/xml; > charset=utf-8 > Date: Fri, 18 Dec 2009 09:44:13 GMT > Expires: Fri, 18 Dec 2009 10:14:13 GMT > Set-Cookie: _twitter_sess=xxx; path=/ > Server: hi > WWW-Authenticate: Basic realm="Twitter API" > > } > > Thank > > On Dec 15, 6:52 pm, Sanjay wrote:> Any Idea out > there? I tried following to no avail: > > > a. Did the entire process (starting from registering the app and > > generating consumer key/secret to getting Access Token/secret. Works > > fine till I get Access Token & Secret > > b. When I copy/paste complete URL in browser's address bar, it prompts > >
[twitter-dev] Re: Desktop App oAuth GET request with valid accesstoken returns 401 Unauthorized
Hey Duane, many thanks for your reply. We did consider the existing .NET libraries but due to some reasons we were to write our own code for basic functionalities. Secondly, with our existing code we completed the process of getting access token and secret key without much problem. I am wondering what could be the issue with our request for verify_credentials? Thanks Sanjay On Dec 18, 6:55 pm, Duane Roelands wrote: > Sanjay, > > There are several really good .NET libraries that handle OAuth > already. > > I would give TweetSharp a look to see if it meets your needs. You > might also want to look at TwitterVB. > > http://tweetsharp.comhttp://twittervb.codeplex.com > > On Dec 18, 5:01 am, Sanjay wrote: >