本文整理汇总了C#中TweetSharp.TwitterService.GetAccessToken方法的典型用法代码示例。如果您正苦于以下问题:C# TwitterService.GetAccessToken方法的具体用法?C# TwitterService.GetAccessToken怎么用?C# TwitterService.GetAccessToken使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TweetSharp.TwitterService
的用法示例。
在下文中一共展示了TwitterService.GetAccessToken方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessAuthoriztion
public LoginProfile ProcessAuthoriztion(HttpContext context, IDictionary<string, string> @params)
{
var twitterService = new TwitterService(KeyStorage.Get("twitterKey"), KeyStorage.Get("twitterSecret"));
if (String.IsNullOrEmpty(context.Request["oauth_token"]) ||
String.IsNullOrEmpty(context.Request["oauth_verifier"]))
{
var requestToken = twitterService.GetRequestToken(context.Request.Url.AbsoluteUri);
var uri = twitterService.GetAuthorizationUri(requestToken);
context.Response.Redirect(uri.ToString(), true);
}
else
{
var requestToken = new OAuthRequestToken { Token = context.Request["oauth_token"] };
var accessToken = twitterService.GetAccessToken(requestToken, context.Request["oauth_verifier"]);
twitterService.AuthenticateWith(accessToken.Token, accessToken.TokenSecret);
var user = twitterService.VerifyCredentials(new VerifyCredentialsOptions());
return ProfileFromTwitter(user);
}
return new LoginProfile();
}
示例2: ReturnFromTwitter
// This URL is registered as the application's callback at http://dev.twitter.com
public ActionResult ReturnFromTwitter(string oauth_token, string oauth_verifier)
{
var requestToken = new OAuthRequestToken { Token = oauth_token };
// Step 3 - Exchange the Request Token for an Access Token
string _consumerKey = System.Configuration.ConfigurationManager.AppSettings["consumerKeyLogin"];
string _consumerSecret = System.Configuration.ConfigurationManager.AppSettings["consumerSecretLogin"];
TwitterService service = new TwitterService(_consumerKey, _consumerSecret);
OAuthAccessToken accessToken = service.GetAccessToken(requestToken, oauth_verifier);
string TwitterToken = accessToken.Token;
string TwitterToeknSecret = accessToken.TokenSecret;
Session[Sessionvars.TwitterRequestToken] = TwitterToken; //You can save this token in your database for pulling user's data in future. this will be save every time while getting permission
Session[Sessionvars.TwitterRequestTokenSecert] = TwitterToeknSecret; //You can save this token in your database for pulling user's data in future. this will be save every time while getting permission
ViewBag.TwitterToken = accessToken.Token;
// Step 4 - User authenticates using the Access Token
//service.AuthenticateWith(accessToken.Token, accessToken.TokenSecret);
//TwitterUser user = service.VerifyCredentials();
//var status = user.Status;
//ViewBag.status = status;
//ViewBag.UserName = user.Name;
//ViewBag.location = user.Location;
//ViewBag.count = user.FollowersCount;
//TwitterDirectMessage Ds = service.SendDirectMessage(user.Id, "hi this test messages");
//service.SendTweet("hi this is test from me at live");
//service.SendTweet("msg", user.Id);
//ViewBag.Userid = service.BeginFollowUserNotifications(user.Id);
return RedirectToAction("Invite");
}
示例3: GetFavorites
public IEnumerable<TwitterStatus> GetFavorites()
{
var service = new TwitterService(Config.Twitter.ConsumerKey, Config.Twitter.ConsumerSecret);
// Step 1 - Retrieve an OAuth Request Token
var requestToken = service.GetRequestToken();
// Step 2 - Redirect to the OAuth Authorization URL
var uri = service.GetAuthorizationUri(requestToken);
Process.Start(uri.ToString());
// Step 3 - Exchange the Request Token for an Access Token
Console.Write("Please, your key? ");
var verifier = Console.ReadLine(); // <-- This is input into your application by your user
var access = service.GetAccessToken(requestToken, verifier);
// Step 4 - User authenticates using the Access Token
service.AuthenticateWith(access.Token, access.TokenSecret);
var users = service.SearchForUser("kellogh");
if (users == null)
{
Console.WriteLine("No users found");
yield break;
}
var user = users.First();
var favorites = service.ListFavoriteTweetsFor(user.Id);
foreach (var tweet in favorites)
{
yield return tweet;
}
}
示例4: ProcessAuthentication
public Account ProcessAuthentication(string pin)
{
TwitterService service = new TwitterService(_consumerKey, _consumerSecret);
OAuthAccessToken access = service.GetAccessToken(_requestToken, pin);
service.AuthenticateWith(access.Token, access.TokenSecret);
var profile = service.GetUserProfile();
Account account = AccountManager.Instance.GetCurrentAccounts().Where(acc => acc.Username == profile.ScreenName).FirstOrDefault();
if (account != null)
{
throw new AuthFailureException("User " +account.Username + " already has an account with TweetOBox.");
}
if (profile != null && account == null)
{
account = new Account();
account.Username = profile.ScreenName;
// account.Password = profile.p
account.AccountType = (int)AccountTypeEnum.Twitter;
account.AccessToken = access.Token;
account.AccessTokenSecret = access.TokenSecret;
account.IsOAuth = true;
AccountManager.Instance.AddAccount(account,false);
}
else
{
throw new AuthFailureException(service.Response.StatusDescription);
}
return account;
}
示例5: GetResponseHtml
public string GetResponseHtml(IDictionary<string, string> parameters, Uri signinUri)
{
var requestToken = new OAuthRequestToken {Token = parameters["oauth_token"]};
// Exchange the Request Token for an Access Token
var service = new TwitterService(Settings.TwitterConsumerKey, Settings.TwitterConsumerSecret);
OAuthAccessToken accessToken = service.GetAccessToken(requestToken, parameters["oauth_verifier"]);
// Claim values
string name = accessToken.ScreenName;
string nameIdentifier = string.Format("https://twitter.com/account/redirect_by_id?id={0}", accessToken.UserId);
string token = accessToken.Token;
string tokenSecret = accessToken.TokenSecret;
string wtRealm = _configurationProvider.Get(Settings.TwitterWtRealm);
string wReply = _configurationProvider.Get(Settings.TwitterWReply);
var requestMessage = new SignInRequestMessage(signinUri, wtRealm, wReply);
// Add claims
var identity = new ClaimsIdentity(AuthenticationTypes.Federation);
identity.AddClaim(new Claim(ClaimTypes.Name, name));
identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, nameIdentifier));
identity.AddClaim(new Claim(TwitterClaims.TwitterToken, token));
identity.AddClaim(new Claim(TwitterClaims.TwitterTokenSecret, tokenSecret));
var principal = new ClaimsPrincipal(identity);
// Serialize response message
SignInResponseMessage responseMessage = FederatedPassiveSecurityTokenServiceOperations.ProcessSignInRequest(requestMessage, principal, this);
responseMessage.Context = parameters["context"];
return responseMessage.WriteFormPost();
}
示例6: GetUserToken
public static void GetUserToken(TwitterService service)
{
// Step 1 - Retrieve an OAuth Request Token
OAuthRequestToken requestToken = service.GetRequestToken();
// Step 2 - Redirect to the OAuth Authorization URL
Uri uri = service.GetAuthorizationUri(requestToken);
Console.WriteLine("Enter this uri into a browser:\n{0}", uri.ToString());
Console.WriteLine("Enter the pin given by twitter");
// Step 3 - Exchange the Request Token for an Access Token
string verifier = Console.ReadLine(); // <-- This is input into your application by your user
OAuthAccessToken access = service.GetAccessToken(requestToken, verifier);
if(access == null)
{
Console.WriteLine("no tokens returned");
return;
}
Console.WriteLine("Access Token:\n{0}", access.Token);
Console.WriteLine("Access Secret:\n{0}", access.TokenSecret);
// Step 4 - User authenticates using the Access Token
service.AuthenticateWith(access.Token, access.TokenSecret);
}
示例7: Main
static void Main(string[] args)
{
var _consumerKey = ConfigurationManager.AppSettings["twitterConsumerKey"].ToString();
var _consumerSecret = ConfigurationManager.AppSettings["twitterConsumerSecret"].ToString();
// configure access token
//var _accessToken = ConfigurationManager.AppSettings["twitterAccess"].ToString();
//var _accessTokenSecret = ConfigurationManager.AppSettings["twitterAccessSecret"].ToString();
service = new TwitterService(_consumerKey, _consumerSecret);
// Step 1 - Retrieve an OAuth Request Token
OAuthRequestToken requestToken = service.GetRequestToken();
// Step 2 - Redirect to the OAuth Authorization URL
Uri uri = service.GetAuthorizationUri(requestToken);
Process.Start(uri.ToString());
// Step 3 - Exchange the Request Token for an Access Token
string verifier = "123456"; // <-- This is input into your application by your user
OAuthAccessToken access = service.GetAccessToken(requestToken, verifier);
// Step 4 - User authenticates using the Access Token
service.AuthenticateWith(access.Token, access.TokenSecret);
//service.AuthenticateWith(_accessToken, _accessTokenSecret);
//SendATweet();
//GeoLocationLookup();
ListFollowers();
Console.ReadKey();
}
示例8: AuthorizeCallback
public static string AuthorizeCallback(string oauthToken, string oauthVerifier)
{
var requestToken = new OAuthRequestToken {Token = oauthToken};
var service = new TwitterService(ConsumerToken.ConsumerKey,
ConsumerToken.ConsumerSecret);
var accessToken = service.GetAccessToken(requestToken, oauthVerifier);
return accessToken.Token;
}
示例9: GetTwitterService
private static TwitterService GetTwitterService(Tuple<string, string> authKeys)
{
TwitterService service = new TwitterService(authKeys.Item1, authKeys.Item2);
OAuthRequestToken requestToken = service.GetRequestToken();
Uri uri = service.GetAuthorizationUri(requestToken);
var taw = new TwitterAuth() { AuthUrl = uri };
taw.ShowDialog();
OAuthAccessToken access = service.GetAccessToken(requestToken, taw.Token);
service.AuthenticateWith(access.Token, access.TokenSecret);
return service;
}
示例10: GetTokens
public static void GetTokens(string oautToken, string verifier, out string token, out string tokenSecret,
out string screenName, out long id)
{
var requestToken = new OAuthRequestToken {Token = oautToken};
var service = new TwitterService(ConsumerToken.ConsumerKey,
ConsumerToken.ConsumerSecret);
var accessToken = service.GetAccessToken(requestToken, verifier);
token = accessToken.Token;
tokenSecret = accessToken.TokenSecret;
screenName = accessToken.ScreenName;
id = accessToken.UserId;
}
示例11: AuthorizeCallback
// This URL is registered as the application's callback at http://dev.twitter.com
public ActionResult AuthorizeCallback(string oauth_token, string oauth_verifier)
{
var requestToken = new OAuthRequestToken { Token = oauth_token, OAuthCallbackConfirmed = true };
TwitterService service = new TwitterService(ConfigurationManager.AppSettings["TwitterConsumerKey"], ConfigurationManager.AppSettings["TwitterConsumerSecret"]);
OAuthAccessToken accessToken = service.GetAccessToken(requestToken, oauth_verifier.ToString());
Session["Twitter.AccessToken"] = accessToken.Token;
Session["Twitter.AccessTokenSecret"] = accessToken.TokenSecret;
return RedirectToAction("Index", "Home");
}
示例12: authTwitter
private void authTwitter(TwitterService twitterService)
{
string authUri = twitterService.GetAuthenticationUrl(requestToken).ToString();
System.Diagnostics.Process.Start(authUri.ToString());
SettingsManager SM = new SettingsManager();
SM.ShowDialog();
pin = SM.twitterPIN;
oAccessToken = twitterService.GetAccessToken(requestToken, pin);
AdvancedSoftwareProject.Properties.Settings.Default.AccessToken = oAccessToken.Token;
AdvancedSoftwareProject.Properties.Settings.Default.AccessTokenSecret = oAccessToken.TokenSecret;
AdvancedSoftwareProject.Properties.Settings.Default.Save();
twitterService.AuthenticateWith(AdvancedSoftwareProject.Properties.Settings.Default.AccessToken, AdvancedSoftwareProject.Properties.Settings.Default.AccessTokenSecret);
}
示例13: LoginCallback
public ActionResult LoginCallback(string returnUrl, string oauth_token, string oauth_verifier)
{
var requestToken = new OAuthRequestToken {Token = oauth_token};
var service = new TwitterService(ConsumerKey, ConsumerSecret);
var accessToken = service.GetAccessToken(requestToken, oauth_verifier);
service.AuthenticateWith(accessToken.Token, accessToken.TokenSecret);
var twitterUser = service.VerifyCredentials(new VerifyCredentialsOptions());
var user = new User {Name = twitterUser.ScreenName, DisplayName = twitterUser.Name, ImageUrl = new Uri(twitterUser.ProfileImageUrl)};
userRepository.Save(user);
FormsAuthentication.SetAuthCookie(user.Name, false);
return Redirect(returnUrl);
}
示例14: AuthorizeCallback
public ActionResult AuthorizeCallback(string oauthToken, string oauthVerifier)
{
var requestToken = new OAuthRequestToken { Token = oauthToken };
// Step 3: Exchange the request token for an access token
TwitterService svc = new TwitterService(_key, _secret);
OAuthAccessToken accessToken = svc.GetAccessToken(requestToken, oauthVerifier);
// Step 4: User authentication using the Access Token
svc.AuthenticateWith(accessToken.Token, accessToken.TokenSecret);
TwitterUser user = svc.VerifyCredentials();
ViewModel.Message = string.Format("Your username is {0}", user.ScreenName);
return View();
}
示例15: AuthorizeCallback
// Registered @ http://dev.twitter.com
public ActionResult AuthorizeCallback(string oauth_token, string oauth_verifier)
{
var requestToken = new OAuthRequestToken { Token = oauth_token };
// Exchange the Request Token for an Access Token
TwitterService service = new TwitterService(_consumerKey, _consumerSecret);
OAuthAccessToken accessToken = service.GetAccessToken(requestToken, oauth_verifier);
// User Authenticates using the Access Token
service.AuthenticateWith(accessToken.Token, accessToken.TokenSecret);
TwitterUser user = service.VerifyCredentials(new VerifyCredentialsOptions());
ViewBag.TwitMessage = "Connected";
return View();
}