401 Unauthorized Access a permissions issue?

Aug 14, 2014 at 11:52 AM
Hi Guys

Im just getting started with c# and the twitter API so I was trying to get the samples in the Examplinvi project working. I have created my application and access keys and added them to the app.config but I keep getting 401 Unauthorized Access errors when I try and run any of the samples.

Currently my application profile only has read access as I need to register a phone number with twitter to upgrade the permissions to read/write. Could that be whats causing the 401 Unauthorized Access? Ive gone through the previous questions posted here with the same issue but none of them resolved it for me.

Cheers
Brian
Coordinator
Aug 14, 2014 at 12:39 PM
Hello there,

It just depends on which method you want to use, if you want to only read information from the Twitter API like tweets and other, this should work properly.
Either case, do not hesitate to give your phone number, they do not use it...

Linvi
Aug 14, 2014 at 1:33 PM
i only tried the to run the CredentialsCreator_WithCaptcha_StepByStep function and it stops on the GetAuthorizationURL function with the 401 error.

I have no problem giving twitter my number but they dont accept it. They are currently only setup to accept phone numbers from one particular mobile network provider and I dont have a number on that network. I can get one but I was hoping to continue on with getting my head around how all this works until I have a number.
Editor
Aug 14, 2014 at 1:52 PM
I think this is a bug.

I had made an issue about this a while ago, it also contains a workaround:
https://tweetinvi.codeplex.com/workitem/2355

Not sure if Linvi got around looking at that workitem.

imlokesh
Aug 14, 2014 at 2:12 PM
I dont think I was getting that error. There were a few runtime ones but the first was always the 401 so I didnt pay much attention to the others. Ill try it again later on and Ill check.

Thanks
Brian
Coordinator
Aug 14, 2014 at 2:16 PM
I will have a look when I have some free time. Please keep posting of you have any news with this problem.
Aug 14, 2014 at 5:56 PM
Ya imlokesh was correct it only appears to affect the step by step function. When I run the single step one its ok and I can connect without any issues.
Aug 14, 2014 at 6:21 PM
Edited Aug 14, 2014 at 6:21 PM
Im having the same issue once I uncomment the filteredstream code

Image
Aug 14, 2014 at 11:35 PM
Im actually having this issue on nearly everything I try and do. Trying to post a tweet and I get 401 unauthorised right after i authenticate so I figure this has to be something im doing wrong

Image
Aug 15, 2014 at 6:15 AM
Brian, have you tried running this without the debugging? I have found that when you do a step debug in Visual Studio, Visual Studio tries to do a "look ahead" and executes some tasks differently than you would like them. This causes a variety of problems in different scenarios. Try to use Output / Debug writes to trace your call. Do you still face the same issue when not stepping through?
Aug 15, 2014 at 6:20 PM
Hi mindless Ive tried it without debug I only turned on debug to try and see where it was failing
Aug 16, 2014 at 7:14 PM
Do you have Fiddler? If not, install it ( http://www.telerik.com/fiddler ) and use it to see what exactly is being requested. You can see the HTTP headers and everything. Since you will be essentially debugging over HTTPS, you will need to say YES to the initial prompt during or just after installation (or was it during first run ??) to install a certificate so that SSL traffic can be decrypted by the tool.
Coordinator
Aug 18, 2014 at 12:51 AM
Hello,

I do not know if this is related with the fact that you do not have a phone number registered but I can use the method without getting any error with simple Read permissions.

Is there anything that I have been missing?

Linvi
Aug 20, 2014 at 10:02 AM
Hi sorry about the delay in getting back to you guys i was away for a few days. I will install fiddler later on and have a look at exactly what is happening during the requests
Aug 20, 2014 at 10:33 PM
Ok so from looking at the responses from twitter I can see Im getting the following message

{"errors":[{"message":"Invalid or expired token","code":89}]}

Im just trawling through google now for some ideas but most seem to be suggesting its an issue with my credentials and Ive treble checked that they are ok and they are the same as the ones returned in the console from twitter
Aug 20, 2014 at 11:28 PM
Ok so its seems I wasnt setting the credentials correctly. I have it working now. I was using

TwitterCredentials.SetCredentials("token_AccessToken", "token_AccessTokenSecret", "token_ConsumerKey", "token_ConsumerSecret");

and I switched to

TwitterCredentials.Credentials = TwitterCredentials.CreateCredentials(userKey, userSecret, consumerKey, consumerSecret);

Everything runs smoot as can be. Cheers for the input. Im sure ill be back for more help once I really start getting into it
Marked as answer by linvi on 8/21/2014 at 2:21 AM