public ActionResult TwitterAuth() { var appCreds = new ConsumerCredentials(CONSUMER_KEY, CONSUMER_SECRET); var redirectURL = "http://" + Request.Url.Authority + "/Home/ValidateTwitterAuth"; var url = CredentialsCreator.GetAuthorizationURL(appCreds, redirectURL); return new RedirectResult(url); }
/// <summary> /// Get the credentials from a PIN CODE/OAUTH VERIFIER provided by twitter.com to the user. /// /// This method generates the credentials from the ConsumerCredentials used to get the Authentication URL. /// </summary> /// <param name="verifierCode"> /// - PIN CODE Authentication : User enters the pin given on twitter.com /// - URL REDIRECT : Use the value of the 'oauth_verifier' url parameter. /// </param> /// <param name="authorizationKey">Authorization Key of the same credentials as the one given as a parameter to get the Authentication URL.</param> /// <param name="authorizationSecret">Authorization Secret of the same credentials as the one given as a parameter to get the Authentication URL.</param> /// <param name="consumerKey">Consumer Key of the same credentials as the one given as a parameter to get the Authentication URL.</param> /// <param name="consumerSecret">Consumer Secret of the same credentials as the one given as a parameter to get the Authentication URL.</param> public static ITwitterCredentials GetCredentialsFromVerifierCode( string verifierCode, string authorizationKey, string authorizationSecret, string consumerKey, string consumerSecret) { var appCredentials = new ConsumerCredentials(consumerKey, consumerSecret) { AuthorizationKey = authorizationKey, AuthorizationSecret = authorizationSecret }; return _credentialsCreator.GetCredentialsFromVerifierCode(verifierCode, appCredentials); }
//private const string TwitterConsumerKey = "unZjcnD6BB0vbU5TfTiXPGnVe"; //private const string TwitterConsumerSecret = "7VoiPTrbqaq1vnuu87U4CAbYDyfiqJwlSanN6LvzGkfQ43f1fj"; // // GET: /Twitter/ public ActionResult Index() { if (Session["TwitterLogin"] != null && Session["TwitterLogin"].ToString() == "YES") return RedirectToAction("Home"); var appCreds = new ConsumerCredentials(TwitterConsumerKey, TwitterConsumerSecret); var redirectURL = "http://userprofiler.azurewebsites.net/twitter/Callback"; //var redirectURL = "http://127.0.0.1/SocialAnalyzer/twitter/Callback"; var url = Tweetinvi.CredentialsCreator.GetAuthorizationURL(appCreds, redirectURL); return Redirect(url); }
public static ITwitterCredentials CredentialsCreator_CreateFromRedirectedVerifierCode_StepByStep(string consumerKey, string consumerSecret) { var applicationCredentials = new ConsumerCredentials(consumerKey, consumerSecret); var url = CredentialsCreator.GetAuthorizationURL(applicationCredentials, "https://tweetinvi.codeplex.com"); Console.WriteLine("Go on : {0}", url); Console.WriteLine("When redirected to your website copy and paste the value of the oauth_verifier : "); // For the following redirection https://tweetinvi.codeplex.com?oauth_token=UR3eTEwDXFNhkMnjqz0oFbRauvAm4YhnF67KE6hO8Q&oauth_verifier=woXaKhpDtX6vhDVPl7TU6955qdQeH3cgz6xDvRZRA4A // Enter the value : woXaKhpDtX6vhDVPl7TU6955qdQeH3cgz6xDvRZRA4A var verifierCode = Console.ReadLine(); // Here we only provide the verifier code var newCredentials = CredentialsCreator.GetCredentialsFromVerifierCode(verifierCode, applicationCredentials); Console.WriteLine("Access Token = {0}", newCredentials.AccessToken); Console.WriteLine("Access Token Secret = {0}", newCredentials.AccessTokenSecret); return newCredentials; }
// Get credentials with callbackURL system public static ITwitterCredentials CredentialsCreator_CreateFromRedirectedCallbackURL_StepByStep(string consumerKey, string consumerSecret) { var applicationCredentials = new ConsumerCredentials(consumerKey, consumerSecret); var url = CredentialsCreator.GetAuthorizationURL(applicationCredentials, "https://tweetinvi.codeplex.com"); Console.WriteLine("Go on : {0}", url); Console.WriteLine("When redirected to your website copy and paste the URL: "); // Enter a value like: https://tweeetinvi.codeplex.com?oauth_token={tokenValue}&oauth_verifier={verifierValue} var callbackURL = Console.ReadLine(); // Here we provide the entire URL where the user has been redirected var newCredentials = CredentialsCreator.GetCredentialsFromCallbackURL(callbackURL, applicationCredentials); Console.WriteLine("Access Token = {0}", newCredentials.AccessToken); Console.WriteLine("Access Token Secret = {0}", newCredentials.AccessTokenSecret); return newCredentials; }
// Get credentials with captcha system // ReSharper disable UnusedMethodReturnValue.Local public static ITwitterCredentials CredentialsCreator_WithCaptcha_StepByStep(string consumerKey, string consumerSecret) { var applicationCredentials = new ConsumerCredentials(consumerKey, consumerSecret); var url = CredentialsCreator.GetAuthorizationURL(applicationCredentials); Console.WriteLine("Go on : {0}", url); Console.WriteLine("Enter the captch : "); var captcha = Console.ReadLine(); var newCredentials = CredentialsCreator.GetCredentialsFromVerifierCode(captcha, applicationCredentials); Console.WriteLine("Access Token = {0}", newCredentials.AccessToken); Console.WriteLine("Access Token Secret = {0}", newCredentials.AccessTokenSecret); return newCredentials; }