本文整理汇总了C#中Twitterizer.OAuthTokens类的典型用法代码示例。如果您正苦于以下问题:C# OAuthTokens类的具体用法?C# OAuthTokens怎么用?C# OAuthTokens使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
OAuthTokens类属于Twitterizer命名空间,在下文中一共展示了OAuthTokens类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetStatus
/// <summary>
/// Gets the rate limiting status status for the authenticated user.
/// </summary>
/// <param name="tokens">The OAuth tokens.</param>
/// <param name="options">The options.</param>
/// <returns>
/// A <see cref="TwitterRateLimitStatus"/> instance.
/// </returns>
public static TwitterResponse<TwitterRateLimitStatus> GetStatus(OAuthTokens tokens, OptionalProperties options)
{
Commands.RateLimitStatusCommand command = new Twitterizer.Commands.RateLimitStatusCommand(tokens, options);
TwitterResponse<TwitterRateLimitStatus> result = Core.CommandPerformer.PerformAction(command);
return result;
}
示例2: Test2
public ActionResult Test2()
{
OAuthTokens tokens = new OAuthTokens { ConsumerKey = ConfigurationManager.AppSettings["TwitterToken"], ConsumerSecret = ConfigurationManager.AppSettings["TwitterTokenSecret"] };
var accounts = Accounts.Get().Select();
foreach (var a in accounts)
{
if (a.Type == AccountType.Twitter)
{
tokens.AccessToken = a.TwKey;
tokens.AccessTokenSecret = a.TwSecret;
TwitterResponse<TwitterStatus> tweetResponse = TwitterStatus.Update(tokens, "Hello, #Twitterizer");
if (tweetResponse.Result == RequestResult.Success)
{
// Tweet posted successfully!
}
else
{
// Something bad happened
}
}
}
return null;
}
示例3: GetMutualFriends
private static IEnumerable<TwitterUser> GetMutualFriends(OAuthTokens tokens)
{
var friends = TwitterFriendship.FriendsIds(tokens);
var followers = TwitterFriendship.FollowersIds(tokens);
var userIds = (from
friendId in friends.ResponseObject
join
followerId in followers.ResponseObject
on friendId equals followerId
select friendId).ToArray();
var lookupOptions = new LookupUsersOptions();
var users = new List<TwitterUser>();
for (int i = 0; i < userIds.Length; i ++)
{
lookupOptions.UserIds.Add(userIds[i]);
if (lookupOptions.UserIds.Count() >= 100 || i + 1 == userIds.Length)
{
users.AddRange(TwitterUser.Lookup(tokens, lookupOptions).ResponseObject);
lookupOptions.UserIds.Clear();
}
}
return users;
}
示例4: Start
public void Start()
{
//TileService.Add<TwitterView>(new TileData
//{
// Title = "Peeps",
// BackgroundImage = new Uri("pack://siteoforigin:,,,/Resources/Tiles/MB_0005_weather1.png")
//});
Task.Factory.StartNew(() =>
{
OAuthTokens tokens = new OAuthTokens();
tokens.AccessToken = "478840940-tgD2Fp5NWXpDPGWyrHTxIjroDODe6F9r8JEkabQ";
tokens.AccessTokenSecret = "Jo4fgjtkYBPTfyuigi3slqOo7lVer7rLXwj6rWs";
tokens.ConsumerKey = "O6MTEfpHhHfhnBr4PuVmlw";
tokens.ConsumerSecret = "lDZgfovK9FEtn8MBsTpGPn8WvuTbGal2yBD4kHLgI";
StreamOptions options = new StreamOptions();
Stream = new TwitterStream(tokens, "v1", options);
Stream.StartUserStream(Friends,
Stopped,
Created,
Deleted,
DirectMessageCreated,
DirectMessageDeleted,
Callback);
Radio.CurrentTrackChanged += RadioOnCurrentTrackChanged;
})
.ContinueWith(task =>
{
if (task.Exception != null)
{
Logger.Log(task.Exception.ToString(), Category.Exception, Priority.Medium);
}
});
}
示例5: AjaxSaveToDB
//
// GET: /Home/
public string AjaxSaveToDB()
{
if (Session["LoggedASP"] != null)
{
TimelineOptions options = new TimelineOptions();
options.Count = 200;
options.IncludeRetweets = true;
OAuthTokens token = new OAuthTokens();
token.ConsumerKey = ConfigurationManager.AppSettings["consumerKey"];
token.ConsumerSecret = ConfigurationManager.AppSettings["consumerSecret"];
token.AccessToken = ((User)Session["LoggedUser"]).TwitterToken;
token.AccessTokenSecret = ((User)Session["LoggedUser"]).TwitterTokenSecret;
TwitterResponse<TwitterStatusCollection> truc = TwitterTimeline.HomeTimeline(token, options);
TweetEntity tweetEntity = new TweetEntity();
tweetEntity.RemoveTweetFromOwner(((User)Session["LoggedUser"]).ID);
foreach (var item in truc.ResponseObject)
{
//int lol = ;
tweetEntity.AddTweet(item.Id, item.Text, item.User.ScreenName, item.User.ProfileImageLocation, ((User)Session["LoggedUser"]).ID, ((int)((TimeSpan)(item.CreatedDate - new DateTime(1970, 1, 1, 0, 0, 0, 0).ToLocalTime())).TotalSeconds));
}
return "Success";
}
else
return "Fail";
}
示例6: TwitterSearchStream
public TwitterSearchStream(TwitterProtocolManager protocolManager,
GroupChatModel chat, string keyword,
OAuthTokens tokens, WebProxy proxy)
{
if (protocolManager == null) {
throw new ArgumentNullException("protocolManager");
}
if (chat == null) {
throw new ArgumentNullException("chat");
}
if (keyword == null) {
throw new ArgumentNullException("keyword");
}
if (tokens == null) {
throw new ArgumentNullException("tokens");
}
ProtocolManager = protocolManager;
Session = protocolManager.Session;
Chat = chat;
var options = new StreamOptions();
options.Track.Add(keyword);
Stream = new TwitterStream(tokens, null, options);
Stream.Proxy = proxy;
Stream.StartPublicStream(OnStreamStopped, OnStatusCreated, OnStatusDeleted, OnEvent);
MessageRateLimiter = new RateLimiter(5, TimeSpan.FromSeconds(5));
}
示例7: frmPrincipal
public frmPrincipal(Twitterizer.OAuthTokens oauth_tokens)
{
//Construtor que recebe o Token do Twitterizer
TOKEN = oauth_tokens;
InitializeComponent();
}
示例8: Tweet
/// <summary>
/// Tweets the given message and image; returns the result.
/// </summary>
/// <param name="message"></param>
public static bool Tweet( string message, byte[] resource )
{
// Check if we need to authenticate first
if ( string.IsNullOrEmpty( Configuration.CurrentSettings.TwitterAccessToken ) || string.IsNullOrEmpty( Configuration.CurrentSettings.TwitterAccessSecret ) )
AcquireAuthentication( );
// Build tokens...
OAuthTokens tokens = new OAuthTokens
{
ConsumerKey = ConsumerKey,
ConsumerSecret = ConsumerSecret,
AccessToken = Configuration.CurrentSettings.TwitterAccessToken,
AccessTokenSecret = Configuration.CurrentSettings.TwitterAccessSecret
};
TwitterResponse<TwitterStatus> response = TwitterStatus.UpdateWithMedia( tokens, message, resource );
if ( response.Result == RequestResult.Success )
log.Info( "Tweeted: " + message );
else
{
if ( response.Result == RequestResult.Unauthorized )
AcquireAuthentication( );
log.Error( "Error during tweet: " + response.Result + " / " + response.ErrorMessage );
return false;
}
return true;
}
示例9: RetrieveTwitts
public IList<NakedTwitt> RetrieveTwitts(int count)
{
List<NakedTwitt> result = new List<NakedTwitt>();
try
{
OAuthTokens tokens = new OAuthTokens()
{
AccessToken = AccessToken,
AccessTokenSecret = AccessTokenSecret,
ConsumerKey = ConsumerKey,
ConsumerSecret = ConsumerSecret
};
TimelineOptions timelineOptions = new TimelineOptions()
{
Count = count,
IncludeRetweets = false
};
TwitterResponse<TwitterStatusCollection> homeTimeline = TwitterTimeline.HomeTimeline(tokens,
timelineOptions);
result =
homeTimeline.ResponseObject.Select(
x => new NakedTwitt() {StringId = x.StringId, Text = x.Text, CreatedDate = x.CreatedDate})
.ToList();
return result;
}
catch (Exception ex)
{
log.Error("Error retrieving twitts from the internet", ex);
return result;
}
}
示例10: Callback
public ActionResult Callback(string oauth_token, string oauth_verifier, bool popup = false)
{
OAuthTokenResponse tokens = OAuthUtility.GetAccessToken(
App.ConsumerKey, App.ConsumerSecret, oauth_token, oauth_verifier);
OAuthTokens oauthTokens = new OAuthTokens();
oauthTokens.AccessToken = tokens.Token;
oauthTokens.AccessTokenSecret = tokens.TokenSecret;
oauthTokens.ConsumerKey = App.ConsumerKey;
oauthTokens.ConsumerSecret = App.ConsumerSecret;
TwitterUser user = TwitterUser.Show(oauthTokens, tokens.UserId).ResponseObject;
Tweeter tweeter = TweeterRepository.FromTwitterId((long)user.Id);
if (tweeter != null)
{
tweeter = Mapper.Map<TwitterUser, Tweeter>(user, tweeter);
}
else
{
tweeter = Mapper.Map<TwitterUser, Tweeter>(user);
TweeterRepository.Save(tweeter);
}
string secureCode = SecurityUtils.GenerateSecureKey(KeyStrength._512bit);
HttpCookie loginCookie = new HttpCookie("Login_Cookie");
loginCookie.Values["ID"] = tweeter.TwitterId.ToString();
loginCookie.Values["Code"] = secureCode;
loginCookie.Expires = DateTime.UtcNow.AddDays(30.0);
loginCookie.HttpOnly = true;
Response.Cookies.Add(loginCookie);
PersistentLogin login = new PersistentLogin(tweeter);
login.SecureKey = secureCode;
login.LastLoginDate = DateTime.UtcNow;
tweeter.PersistentLogins.Add(login);
TweeterRepository.Save(tweeter);
Tweeter = tweeter;
if (!popup)
{
string referrerUrl = GetTempReferrerUrl();
if (!String.IsNullOrWhiteSpace(referrerUrl))
{
return Redirect(referrerUrl);
}
return RedirectToAction("Latest", "Display");
}
else
{
return View("Complete", Tweeter);
}
}
示例11: VerifyButton_Click
protected void VerifyButton_Click(object sender, EventArgs e)
{
ResultLabel.Visible = true;
OAuthTokens tokens = new OAuthTokens()
{
AccessToken = AKTextBox.Text,
AccessTokenSecret = ASTextBox.Text,
ConsumerKey = CKTextBox.Text,
ConsumerSecret = CSTextBox.Text
};
TwitterResponse<TwitterErrorDetails> twitterResponse = TwitterAccount.EndSession(tokens, null);
if (twitterResponse.Result == RequestResult.Success)
{
ResultLabel.Text = string.Format("Success! Verified as {0}", twitterResponse.ResponseObject.ErrorMessage);
ResultLabel.CssClass = "ResultLabelSuccess";
}
else
{
ResultLabel.Text = string.Format("Failed! \"{0}\"", twitterResponse.ErrorMessage ?? "Not Authorized.");
ResultLabel.CssClass = "ResultLabelFailed";
}
}
示例12: VerifyCredentials
/// <summary>
/// Attempts to verify the supplied credentials.
/// </summary>
/// <param name="tokens">The tokens.</param>
/// <param name="timeout">The timeout.</param>
/// <param name="function">The callback or anonymous funtion.</param>
/// <returns>
/// The user, as a <see cref="TwitterUser"/>
/// </returns>
public static IAsyncResult VerifyCredentials(OAuthTokens tokens, TimeSpan timeout, Action<TwitterAsyncResponse<TwitterUser>> function)
{
#if !SILVERLIGHT
Func<OAuthTokens, TwitterResponse<TwitterUser>> methodToCall = TwitterAccount.VerifyCredentials;
return methodToCall.BeginInvoke(
tokens,
result =>
{
result.AsyncWaitHandle.WaitOne(timeout);
try
{
function(methodToCall.EndInvoke(result).ToAsyncResponse());
}
catch (Exception ex)
{
function(new TwitterAsyncResponse<TwitterUser>() { Result = RequestResult.Unknown, ExceptionThrown = ex });
}
},
null);
#else
ThreadPool.QueueUserWorkItem((x) =>
{
function(TwitterAccount.VerifyCredentials(tokens).ToAsyncResponse<TwitterUser>());
});
return null;
#endif
}
示例13: Tweet
public static void Tweet(string message)
{
throw new NotSupportedException("Remove this when you're ready to Tweet!");
try
{
if (ConfigManager.CurrentUserSpecific.IsValidated)
return;
if (ConfigManager.CurrentUserSpecific.IsEnabled == false)
return;
var currConfig = ConfigManager.CurrentUserSpecific;
OAuthTokens tokens = new OAuthTokens
{
ConsumerKey = ConsumerKey,
ConsumerSecret = ConsumerSecret,
AccessToken = currConfig.AccessToken,
AccessTokenSecret = currConfig.AccessSecret
};
TwitterResponse<TwitterStatus> tweetResponse = TwitterStatus.Update(tokens, message);
if (tweetResponse.Result == RequestResult.Success)
{
// Tweet posted successfully!
}
else
{
// Something bad happened
}
} catch // Very silent
{
}
}
示例14: GetTwittUser
/*Retrieve a twitt user from a given screen name, see https://dev.twitter.com/docs/api/1/get/users/show*/
public static TwittUser GetTwittUser(string screenName)
{
OAuthTokens tokens = new OAuthTokens();
tokens.ConsumerKey = "Removed from github example";
tokens.ConsumerSecret = "Removed from github example";
tokens.AccessToken = "Removed from github example";
tokens.AccessTokenSecret = "Removed from github example";
var list = new List<string>();
LookupUsersOptions options = new LookupUsersOptions(){UseSSL = true, APIBaseAddress="http://api.twitter.com/1.1/"};
options.ScreenNames.Add(screenName);
TwitterResponse<TwitterUserCollection> res = TwitterUser.Lookup(tokens, options);
TwitterUserCollection users = res.ResponseObject;
TwitterUser user = users.First();
if (user == null) return null;
TwittUser tu = new TwittUser(
user.Id.ToString(),
user.Name,
user.ScreenName,
user.Location,
user.Description);
return tu;
}
示例15: GetTwittStatusList
public static List<TwittStatus> GetTwittStatusList(string screenName)
{
OAuthTokens tokens = new OAuthTokens();
tokens.ConsumerKey = "zPY6AwGePUOWAk0fTvrhZhgzg";
tokens.ConsumerSecret = "VzBhawh55oWWocdDrn4MdLfSPcG5ypf7scFJZGrSyWkSuJAjDA";
tokens.AccessToken = "50022775-djO15EBUOMT76TXswKa0XvwfDmM12Xo27NZmxyhwr";
tokens.AccessTokenSecret = "QqpnD1Mq4AEQYW48NyauzAMDRGDyQ0QCTQjWNRFyFCZkz";
var list = new List<TwittStatus>();
UserTimelineOptions options = new UserTimelineOptions();
options.APIBaseAddress = "https://api.twitter.com/1.1/";
options.Count = 20;
options.UseSSL = true;
options.ScreenName = screenName;
var resp = TwitterTimeline.UserTimeline (tokens, options);
TwitterStatusCollection tweets = resp.ResponseObject;
if (tweets == null) return null;
foreach (var status in tweets) {
TwittStatus ts = new TwittStatus (
status.Id.ToString (),
status.Text,
status.User.Id.ToString(),
status.CreatedDate.ToString());
list.Add (ts);
}
return list;
}