本文整理汇总了C#中TweetSharp.TwitterService类的典型用法代码示例。如果您正苦于以下问题:C# TwitterService类的具体用法?C# TwitterService怎么用?C# TwitterService使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TwitterService类属于TweetSharp命名空间,在下文中一共展示了TwitterService类的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: bw_DoWork
private void bw_DoWork(object sender, DoWorkEventArgs e)
{
TwitterService service = new TwitterService(consumerKeyTextBox.Text, consumerSecretTextBox.Text, accessTokenTextBox.Text, accessTokenSecretTextBox.Text);
TwitterUser user = service.VerifyCredentials();
if (service.Response.InnerException != null)
{
TwitterError error = service.Deserialize<TwitterError>(service.Response.Response);
if (!string.IsNullOrEmpty(error.ErrorMessage))
{
e.Result = error; // return the error object on failure
}
else
{
e.Result = null; // err, dunno. return null
}
}
else if (user != null)
{
e.Result = user; // return user object on success
}
else
{
e.Result = null; // unknown error
}
}
示例3: GetAuthenticatedService
public TwitterService GetAuthenticatedService()
{
var twitterClientInfo = new TwitterClientInfo {ConsumerKey = ConsumerKey, ConsumerSecret = ConsumerSecret};
twitterService = new TwitterService(twitterClientInfo);
twitterService.AuthenticateWith(AccessToken, AccessTokenSecret);
return twitterService;
}
示例4: LoadTweets
public static IReadOnlyCollection<PoliticalTweet> LoadTweets( IEnumerable<string> handles )
{
var service = new TwitterService( ConsumerKey, ConsumerSecret );
service.AuthenticateWith( AccessToken, AccessTokenSecret );
var results = new List<PoliticalTweet>();
foreach ( var handle in handles.Distinct() )
{
try
{
var response = service.ListTweetsOnUserTimeline( new ListTweetsOnUserTimelineOptions
{
ScreenName = handle,
Count = 200,
IncludeRts = false,
ExcludeReplies = true
} );
results.AddRange( response.Select( t => new PoliticalTweet( handle, t.Text, t.CreatedDate, t.IdStr ) ) );
Debug.WriteLine( $"{service.Response.RateLimitStatus.RemainingHits} remaining hits." );
if ( service.Response.RateLimitStatus.RemainingHits <= 0 )
{
var wait = service.Response.RateLimitStatus.ResetTime.ToUniversalTime() - DateTime.UtcNow;
Debug.WriteLine( $"Rate limit reached. Sleeping for {wait}." );
Thread.Sleep( wait );
}
}
catch
{
Debug.WriteLine( $"Skipping {handle}" );
}
}
return results;
}
示例5: 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");
}
示例6: Login
public ActionResult Login(string returnUrl)
{
var service = new TwitterService(ConsumerKey, ConsumerSecret);
var requestToken = service.GetRequestToken(Url.Action("LoginCallback", "Auth", new {returnUrl}, Request.Url.Scheme));
var uri = service.GetAuthorizationUri(requestToken);
return Redirect(uri.ToString());
}
示例7: Main
public static void Main(string[] args)
{
var service = new TwitterService(consumerKey, consumerSecret);
// GetUserToken(service);
ListenOnUserStream(service);
}
示例8: Main
static void Main(string[] args)
{
TwangManSays("********************************************");
TwangManSays("* HANG THE TWANG *");
TwangManSays("********************************************");
CurrentGames = new Dictionary<long, TwitterThread>();
tweetsToSend = new ConcurrentQueue<SendArgs>();
TwitterSender = new Task(DoWork);
TwitterSender.Start();
_sendService = new TwitterService(Authentication.ConsumerKey, Authentication.ConsumerSecret);
_sendService.AuthenticateWith(Authentication.AccessToken, Authentication.AccessTokenSecret);
_service = new TwitterService(Authentication.ConsumerKey, Authentication.ConsumerSecret);
_service.AuthenticateWith(Authentication.AccessToken, Authentication.AccessTokenSecret);
TwitterListener = new Task(Listen);
TwitterListener.Start();
Console.ReadLine();
_service.CancelStreaming();
}
示例9: GetUser
public TwitterUser GetUser(LoginModel model)
{
var twitterService = new TweetSharp.TwitterService(ConsumerKey, ConsumerSecret);
twitterService.AuthenticateWith(model.Token, model.Secret);
TwitterUser user = twitterService.VerifyCredentials(new VerifyCredentialsOptions() { IncludeEntities = false, SkipStatus = false });
return user;
}
示例10: Post
public override void Post()
{
if ((String.IsNullOrEmpty(token = Config.TwitterAccessToken)
|| String.IsNullOrEmpty(tokenSecret = Config.TwitterTokenSecret))
&& !this.Auth())
{
App.Instance.AddError(Config.AUTHORIZATION_ERROR_EN, Config.TWITTER_TITLE);
return;
}
else
{
//Authorize with the saved access token and secret
TwitterClientInfo twitterClientInfo = new TwitterClientInfo();
twitterClientInfo.ConsumerKey = ConsumerKey;
twitterClientInfo.ConsumerSecret = ConsumerSecret;
TwitterService twitterService = new TwitterService(twitterClientInfo);
//twitterService.AuthenticateWith(token, tokenSecret);
}
try
{
this.PostTweet();
}
catch (Exception)
{
App.Instance.AddError(Config.TWITTER_ERROR, Config.TWITTER_TITLE);
}
}
示例11: TweetViewModel
public TweetViewModel(ITweetTimer tweetTimer, TwitterService service)
{
this.tweetTimer = tweetTimer;
this.service = service;
Tweets = new BindableCollection<Tweet>();
}
示例12: 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;
}
示例13: UploadPhoto
///
/// Uploads the photo and sends a new Tweet
///
/// <param name="binaryImageData">The binary image data.
/// <param name="tweetMessage">The tweet message.
/// <param name="filename">The filename.
/// Return true, if the operation was succeded.
public string UploadPhoto(string imageFile, string tpkey, string usrtoken, string usrsecret, string contoken, string consecret)
{
TwitterService service = new TwitterService(contoken, consecret);
service.AuthenticateWith(usrtoken, usrsecret);
Hammock.RestRequest request = service.PrepareEchoRequest();
request.Path = "upload.xml";
request.AddFile("media", "uploadfile", imageFile, "image/jpeg");
request.AddField("key", tpkey);
Hammock.RestClient client = new Hammock.RestClient() { Authority = "http://api.twitpic.com", VersionPath = "2" };
Hammock.RestResponse response = client.Request(request);
if (response.StatusCode == HttpStatusCode.OK)
{
XDocument doc = XDocument.Parse(response.Content);
XElement image = doc.Element("image");
return image.Element("url").Value;
}
else
throw new Exception("Error occured while uploading image to TwitPic servers. Please try again later");
return "";
}
示例14: Connect
private void Connect(string consumerKey, string consumerSecret, string accessToken, string accessTokenSecret)
{
// In v1.1, all API calls require authentication
var service = new TwitterService(consumerKey, consumerSecret);
service.AuthenticateWith(accessToken, accessTokenSecret);
Log("Connected");
TwitterRateLimitStatusSummary rate = service.GetRateLimitStatus(new GetRateLimitStatusOptions());
Log("Limimte rate: " + rate.RawSource);
var tweets = service.ListTweetsOnHomeTimeline(new ListTweetsOnHomeTimelineOptions());
foreach (var tweet in tweets)
{
Console.WriteLine("{0} says '{1}'", tweet.User.ScreenName, tweet.Text);
}
TwitterCursorList<TwitterUser> friends = service.ListFollowers(new ListFollowersOptions());
Log("Friends: " + friends.Count);
foreach (var friend in friends)
{
Log(String.Format("Friend: {0}", friend.Name));
}
}
示例15: TwitterWrapper
public TwitterWrapper()
{
Service = new TwitterService(ConfigurationManager.AppSettings["consumerAccessorA"], ConfigurationManager.AppSettings["consumerAccessorB"]);
Service.AuthenticateWith(ConfigurationManager.AppSettings["authTokenA"], ConfigurationManager.AppSettings["authTokenB"]);
// Ha. I hope you don't use your Twitter account for anything else, Ryan...
Service.IncludeRetweets = true;
}