本文整理汇总了C#中TweetSharp.TwitterService.GetAccessTokenWithXAuth方法的典型用法代码示例。如果您正苦于以下问题:C# TwitterService.GetAccessTokenWithXAuth方法的具体用法?C# TwitterService.GetAccessTokenWithXAuth怎么用?C# TwitterService.GetAccessTokenWithXAuth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TweetSharp.TwitterService
的用法示例。
在下文中一共展示了TwitterService.GetAccessTokenWithXAuth方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Authorize
//
// GET: /Twitter/
public ActionResult Authorize()
{
// OAuth Access Token Exchange
TwitterService service = new TwitterService("consumerKey", "consumerSecret");
OAuthAccessToken access = service.GetAccessTokenWithXAuth("username", "password"); //
return View();
}
示例2: Authenticate
public Account Authenticate(string userName, string password)
{
if (String.IsNullOrEmpty(userName) || String.IsNullOrEmpty(password))
{
throw new ArgumentNullException("userName");
}
TwitterService service = new TwitterService(ConfigurationManager.AppSettings["ConsumerKey"],
ConfigurationManager.AppSettings["ConsumerSecret"]);
OAuthAccessToken access = service.GetAccessTokenWithXAuth(userName, password);
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;
}
示例3: getTweets
/// <summary>
/// uses the tweetsharp api to get all tweets for the given company
/// </summary>
/// <param name="companyname">the name of the company</param>
/// <returns>all tweets formated for the input string for the sentiment analysis</returns>
private string getTweets(string companyname)
{
Console.WriteLine("Getting the tweets...");
TwitterService twitterService = new TwitterService("H70mkcnY9uKDDGUcKywlBA", "fiobr6kG9OKwNHIU5D18dbpxWE5KdxWD8GRPRhMVII");
OAuthAccessToken access = twitterService.GetAccessTokenWithXAuth("2012AIC", "!aicgroup");
ArrayList pages = new ArrayList();
JsonSerializer serializer = new JsonSerializer();
// you can changes this number to get more tweets (100 tweets per page)
int numPages = 1;
// get the tweets from the first x numpages
for (int i = 1; i <= numPages; i++)
{
TwitterSearchResult response = twitterService.Search(companyname, i, 100);
RootObject page = (RootObject)serializer.Deserialize(new JsonTextReader(new StringReader(response.RawSource)), typeof(RootObject));
pages.Add(page);
}
string result = "{'data': [";
int count = 0;
int eng = 0;
foreach (RootObject curPage in pages)
{
foreach (var tweet in curPage.results)
{
count++;
if (tweet.iso_language_code.Equals("en"))
{
eng++;
string tweettext = tweet.text;
tweettext = replaceChars(tweettext);
result += "{'text': '" + tweettext + "', 'query': '" + companyname + "'}, ";
}
}
}
Console.WriteLine(count + " tweets fetched, " + eng + " were english and saved for the sentiment analysis.\n");
// get rid of the last comma
result = result.Substring(0, result.Length - 2);
result += "]}";
return result;
}
示例4: TestWithTweetSharpXAuth
private static void TestWithTweetSharpXAuth()
{
// OAuth Access Token Exchange
TwitterService twitterService = new TwitterService(OAuthProperties.ConsumerKey, OAuthProperties.ConsumerKeySecret);
twitterService.AuthenticateWith(OAuthProperties.AccessToken, OAuthProperties.AccessTokenSecret);
Console.WriteLine("Enter Username...");
string username = Console.ReadLine();
Console.WriteLine("Enter Password...");
string password = Console.ReadLine();
OAuthAccessToken accessToken = twitterService.GetAccessTokenWithXAuth(username, password);
twitterService.AuthenticateWith(accessToken.Token, accessToken.TokenSecret);
var verifyCredentialsOptions = new VerifyCredentialsOptions { IncludeEntities = true };
TwitterUser user = twitterService.VerifyCredentials(verifyCredentialsOptions);
}