In using some of the twitter apps such as Tweetings Janetter etc. You authenticate once and enter your auth pincode and since then i haven't had to authenticate again for atleast 3+ weeks
In using the .net api's such as Spring.Net Social Twitter example ConsoleQuickStart, skipping the
line
Process.Start(authenticateUrl);
and entering the code from previous app runtime does not work and throws and exception
whereas shutting down other twitter apps such as tweetings does not require re-authentication !!
Any help on how to reuse tokens and general rules on good behavior for such reuse ?
thanks
The example is at
https://github.com/SpringSource/spring-net-social-twitter/blob/master/examples/Spring.ConsoleQuickStart/src/Spring.ConsoleQuickStart/Program.cs
UPDATE -
Now getting a HTTP 401 Unauthorized after changing the code to this -
if ( ! haveOAuthAndPin )
{
var oauthToken = twitterServiceProvider.OAuthOperations.FetchRequestTokenAsync("oob", null).Result;
string authenticateUrl = twitterServiceProvider.OAuthOperations.BuildAuthorizeUrl(oauthToken.Value, null);
Console.WriteLine("Redirect user for authentication: " + authenticateUrl);
Process.Start(authenticateUrl);
Console.WriteLine("Enter PIN Code from Twitter authorization page:");
pinCode = Console.ReadLine();
StoreAuthTokenAndPin(oAuthToken, pinCode);
}
else
{
var oAuthToken = new oAuthToken(storedValue, storedSecret)
pinCode = storedPinCode ;
}
the complete error stack is -
System.AggregateException was unhandled
HResult=-2146233088
Message=One or more errors occurred.
Source=mscorlib
StackTrace:
at System.AggregateException.Handle(Func`2 predicate)
at Spring.ConsoleQuickStart.Program.Main(String[] args) in C:\downloads\_source-code\Spring.net\Spring.Social.Twitter-2.0.0-M1\examples\Spring.ConsoleQuickStart\src\Spring.ConsoleQuickStart\Program.cs:line 168
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException: System.AggregateException
HResult=-2146233088
Message=One or more errors occurred.
Source=mscorlib
StackTrace:
at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
at Spring.Social.OAuth1.OAuth1Template.<ExchangeForAccessTokenAsync>b__1(Task`1 task) in f:\bamboo-home\xml-data\build-dir\SPRNETSOCIAL-RELEASE-JOB1\src\Spring.Social.Core\Social\OAuth1\OAuth1Template.cs:line 233
at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()
at System.Threading.Tasks.Task.Execute()
InnerException: Spring.Rest.Client.HttpClientErrorException
HResult=-2146233088
Message=POST request for 'https://api.twitter.com/oauth/access_token' resulted in 401 - Unauthorized (Unauthorized).
Source=Spring.Rest
StackTrace:
at Spring.Rest.Client.Support.DefaultResponseErrorHandler.HandleError(Uri requestUri, HttpMethod requestMethod, HttpResponseMessage`1 response) in f:\bamboo-home\xml-data\build-dir\SPRNETREST-RELEASE-JOB1\src\Spring.Rest\Rest\Client\Support\DefaultResponseErrorHandler.cs:line 121
at Spring.Rest.Client.Support.DefaultResponseErrorHandler.HandleError(Uri requestUri, HttpMethod requestMethod, IClientHttpResponse response) in f:\bamboo-home\xml-data\build-dir\SPRNETREST-RELEASE-JOB1\src\Spring.Rest\Rest\Client\Support\DefaultResponseErrorHandler.cs:line 86
at Spring.Rest.Client.RestTemplate.HandleResponseError(Uri uri, HttpMethod method, IClientHttpResponse response, IResponseErrorHandler errorHandler) in f:\bamboo-home\xml-data\build-dir\SPRNETREST-RELEASE-JOB1\src\Spring.Rest\Rest\Client\RestTemplate.cs:line 2959
at Spring.Rest.Client.RestTemplate.ResponseReceivedCallback[T](ClientHttpRequestCompletedEventArgs responseReceived) in f:\bamboo-home\xml-data\build-dir\SPRNETREST-RELEASE-JOB1\src\Spring.Rest\Rest\Client\RestTemplate.cs:line 2777
InnerException: