Problem when logging in again

Dec 16, 2014 at 10:33 AM
Edited Dec 16, 2014 at 10:33 AM
Hi,

I try to make a desktop application that reads tweets of a few users and uses the data on a server. The user should be able to log in in my case. Therefore I tried to display the Authorization-Web-Page once. Afterwards I store the login data (AccessToken and AccessTokenSecret) into a file.

If the application will be restarted I tried to do the login again without displaying the web page. I tried to use the login data (AccessToken and its Secret) again to log in.
Therefore I tried something this:

TwitterCredentials.SetCredentials(AccessToken, AccessTokenSecret, ConsumerKey, ConsumerSecret);
        IOAuthCredentials cred = TwitterCredentials.Credentials;
        credentials = cred;

        TwitterCredentials.ApplicationCredentials = cred;
        TwitterCredentials.Credentials = cred; // With or without. no change
        TwitterCredentials.CredentialsAccessor.CurrentThreadCredentials = cred; // With or without. no change
        TwitterCredentials.CredentialsAccessor.ApplicationCredentials = cred; // With or without. no change

After the relogin there is no exception but if I try to call GetUserTimelineAsync(...) I get something like this:
CreationDate: {16.12.2014 11:06:33}
StatusCode: 400
TwitterDescription: null
TwitterExceptionInfos: Count = 1
URL: "https://api.twitter.com/1.1/users/show.json?user_id=XXXXX"
I hope you could help me. Maybe its just a stupid mistake. I don't know how to solve this.
Thanks
Dec 17, 2014 at 3:42 AM
Hey,

Can you try using the method TwitterCredentials.SetCredentials? That's what I use, so I'm not sure the way you're setting credentials should work or not.

imlokesh
Marked as answer by CHF on 2/10/2015 at 1:15 AM
Dec 22, 2014 at 7:02 AM
Thanks for your help imlokesh.
Now I use
TwitterCredentials.SetCredentials(AccessToken, AccessTokenSecret, ConsumerKey, ConsumerSecret);
but the problem somehow stays the same.. Could it be a problem because it is done in another thread?
Dec 22, 2014 at 8:53 AM
It seems like I found the problem..
If I debug the Application the Tweetinvi.TwitterCredentials Object contains "ApplicationCredentials" "Credentials" and "CredentialsAccessor" directly after the re-login.
After some time in another thread the "Credentials" value is NULL. If I do something like this (in the current Thread):
TwitterCredentials.SetCredentials(TwitterCredentials.ApplicationCredentials);
The Application works fine again.

Is there something I did wrong in the re-login procedure so that the data is not available to all threads?