Skip to content

Instantly share code, notes, and snippets.

@cannorin
Created October 18, 2015 09:38
Show Gist options
  • Save cannorin/61a3a2c6c2bb7ee3a396 to your computer and use it in GitHub Desktop.
Save cannorin/61a3a2c6c2bb7ee3a396 to your computer and use it in GitHub Desktop.
// CoreTweet for Shell
//
// Required Files:
// CoreTweet.Streaming.Reactive.dll CoreTweet.dll Newtonsoft.Json.dll
//
// * Place this script and required dlls into $HOME/.scripts/csharp .
// * You need a consumer key and a consumer secret key.
// * Your data will be saved to $HOME/.twtokens .
// * Your tokens will be appear as an variable 'tokens' and 'apponly'.
using CoreTweet;
using CoreTweet.Core;
LoadAssembly("System.Runtime.Serialization");
using System.Xml;
using System.Runtime.Serialization;
using System.IO;
Tokens tokens;
OAuth2Token apponly;
if(true)
{
var ds = new DataContractSerializer(typeof(TokensBase[]));
var tf = ".twtokens";
var home = (Environment.OSVersion.Platform == PlatformID.Unix || Environment.OSVersion.Platform == PlatformID.MacOSX) ? Environment.GetEnvironmentVariable("HOME") : Environment.ExpandEnvironmentVariables("%HOMEDRIVE%%HOMEPATH%");
var tpath = Path.Combine(home, tf);
if(!File.Exists(tpath)) {
Console.WriteLine
(@"== CoreTweet for Shell ==
== Setup Wizard ==
* You need a consumer key and a consumer secret key.
* Your data will be saved to {0} .
* Your tokens will be appear as an variable 'tokens' and 'apponly'.
");
Console.Write("consumer key>");
var ck = Console.ReadLine();
Console.Write("consumer secret>");
var cs = Console.ReadLine();
var a = OAuth.Authorize(ck, cs);
Console.WriteLine(a.AuthorizeUri);
Console.Write("pin>");
tokens = a.GetTokens(Console.ReadLine());
apponly = OAuth2.GetToken(ck, cs);
using(var f = File.OpenWrite(tpath))
ds.WriteObject(f, new TokensBase[]{tokens, apponly});
Console.WriteLine("Saved to {0} .", tpath);
} else using (var f = File.OpenRead(Path.Combine(home, tf)))
{
var t = (TokensBase[])ds.ReadObject(f);
tokens = (Tokens)t[0]; apponly = (OAuth2Token)t[1];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment