Unauthorized

Jan 27, 2014 at 4:12 PM
Hi linvi: I was using Tweetinvi to publish tweets. I was working fine,but yesterday i encapsulated code in a Service (svc project) and run it in another PC. Now i get 401 Unauthorized error. My code is very basic:

// Initializing a Token with Twitter Credentials contained in the App.config
        IToken token = new Token(
            ConfigurationManager.AppSettings["token_AccessToken"],
            ConfigurationManager.AppSettings["token_AccessTokenSecret"],
            ConfigurationManager.AppSettings["token_ConsumerKey"],
            ConfigurationManager.AppSettings["token_ConsumerSecret"]);

        ITweet t = new Tweet("From " + device_Name + ":" + tweet_Tex + "." + follow_link);
        return t.Publish(token);
I´m missing something?? In the previus machine the service run ok. I checked the network configuration and is the same.

Regards
Coordinator
Jan 27, 2014 at 4:41 PM
Hi,

The problem is strange. Consequently would you please answer the following questions :)

Are the Tweetinvi version the same on both machine?
Is your Tweetinvi API version the 0.8.3.23 or 0.9? If no please update ;)
If I understand correctly you've tried using the webservice locally on your machine and it was working perfectly?
Have you verified that the configuration file on your server contains the values for the Token?
Have you debbugged your distant webservice (on the new server) and verified the credentials?

A lot of questions I know :)
Linvi
Jan 27, 2014 at 4:53 PM
Hi, thanks for answer so quickly.

The version that i´m using is 08.3.23 and is the same version in both PC.
Actually, I,m using the service locally in both machines.In the first one works perfectly. The second, none. The token values are fine. I just copied the application from one pc to another.

Maybe i made a mistake creating the token???
I read in the documentation that first i need go to an url an accept the app for the user. But untill now, it was working fine without do that.
Coordinator
Jan 27, 2014 at 5:02 PM
__Maybe i made a mistake creating the token???
I read in the documentation that first i need go to an url an accept the app for the user. But untill now, it was working fine without do that.__

The TokenCreator needs to be used for users of your application. It is in fact used to create a Token but if you already have credentials (from the dev.twitter.com), you do not need to accept the app.

Now that you have replied to all my questions I can tell that I am very confused with your issue.

To ensure that you are not posting the same Tweet twice which is not authorized by Twitter. Would you please try to change this line:
 ITweet t = new Tweet("From " + device_Name + ":" + tweet_Tex + "." + follow_link + Guid.NewGuid());
If this is not the problem I believe I will need to debug your application with you on a Skype meeting.
Contact me on my contact form and we can fix a meeting tonight.

Regards,
Linvi
Jan 27, 2014 at 5:12 PM
I replaced the line but i keep getting the same error. But when debugging, I notice that token variable has a property with an Exception.
The property is ServerDateTimeOfPreviousRequest and the exception is :

Message = "You cannot access the server datetime before performing any HttpRequest"

The StackTrace said:
StackTrace = " at TwitterToken.Token.get_ServerDateTimeOfPreviousRequest() in c:\Users\Thomas\Documents\Tweetinvi\Release\TwitterToken\Token.cs:line 39"

Maybe thats the problem?
Coordinator
Jan 27, 2014 at 5:25 PM
No this is not the issue.
Each time a query is perform the ServerDateTimeOfPreviousRequest property is updated to the Time provided by Twitter servers.
This property sends an exception if no query has yet been performed. So this is not the issue.

Linvi
Coordinator
Jan 27, 2014 at 5:29 PM
Can you please try to hard code the values of your credentials instead of using the ConfigurationManager?
IToken token = new Token("YOUR_CREDENTIAL", "YOUR_CREDENTIAL", "YOUR_CREDENTIAL", "YOUR_CREDENTIAL");
Please let me know what happens.
Jan 27, 2014 at 6:17 PM
Hi linvi. It remains the same. I´ll spend some time comparing again the PC´s configurations. It´s a nonsense that in one machine works and not in the other. Now, just to be sure: ¿Are the following the steps to use Tweetinvi from scracht?

1-First I create my twitter app in dev.twitter.com
2-Chance the permisions to Read, Write and Direct Messages
3-Get the access tokens(access and secret)
4-Copy this four values (consumer and token) and use to create a IToken like this:

IToken token = new Token(
        ConfigurationManager.AppSettings["token_AccessToken"],
        ConfigurationManager.AppSettings["token_AccessTokenSecret"],
        ConfigurationManager.AppSettings["token_ConsumerKey"],
        ConfigurationManager.AppSettings["token_ConsumerSecret"]);
5- Once the IToken was created, I can use the Twitter API without problem.

I´m correct or i´m missing something?
Coordinator
Jan 27, 2014 at 6:23 PM
Yes it is exactly the process you need to follow. Just by curiosity can you try using the development version.
Please do not hesitate to contact me personally if you think I can help you in live.

Linvi
Jan 27, 2014 at 7:06 PM
Hi linvi, thanks for the help. Unfortunaly, the access to internet is very dificult to me.

Thanks again.
Coordinator
Jan 27, 2014 at 8:23 PM
Sure,

In that case, please let me know how your investigation is going on and please feel free to ask any question, I do not like not being able to help solve issues.

Linvi
Jan 28, 2014 at 4:56 PM
Hi linvi. Yesterday I send the app to a friend an it works fine. So, in conclusion, Tweetinvi is fine and the second PC is crazy, hahahaha. Sorry for that. I´m writing to you just to let you now. If you are agree, i,ll keep this thread open, because i still searching the reasons. ¿Maybe a proxy problem can return a 401 error?

Regards...
Coordinator
Jan 28, 2014 at 5:33 PM
If you are agree, i,ll keep this thread open
Sure, you are almost the first one who would have closed a thread ;p

Maybe a proxy problem can return a 401 error?
It can be a proxy issue but I am not sure this is a proxy error.
You can use the Exception manager to get more details related with your exception.

There are examples in Examplinvi, I will send you more details when I can.

Linvi
Jan 30, 2014 at 2:00 PM
Hi linvi: The problem was solved. It just the time configuration in the PC. This happend because I didn´t read the first page of the documentation. Yesterday I did and notice the problem. Now the service is working great. Thanks for your time. I hope you can use this in others threads.

Regards.
Marked as answer by maquert on 1/30/2014 at 6:03 AM
Coordinator
Jan 30, 2014 at 5:42 PM
I am glad you solved your bug. I rarely think about this issue, I will try to remember it :)

Thank you
And Enjoy Tweetinvi ;)