本文整理汇总了C#中OAuthTokens类的典型用法代码示例。如果您正苦于以下问题:C# OAuthTokens类的具体用法?C# OAuthTokens怎么用?C# OAuthTokens使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
OAuthTokens类属于命名空间,在下文中一共展示了OAuthTokens类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetHomeTimeLineAsync
public async Task<IEnumerable<TwitterSchema>> GetHomeTimeLineAsync(OAuthTokens tokens)
{
try
{
var uri = new Uri("https://api.twitter.com/1.1/statuses/home_timeline.json");
var rawResult = await _request.ExecuteAsync(uri, tokens);
var result = JsonConvert.DeserializeObject<TwitterTimeLineItem[]>(rawResult);
return result
.Select(r => new TwitterSchema(r))
.ToList();
}
catch (WebException wex)
{
HttpWebResponse response = wex.Response as HttpWebResponse;
if (response != null)
{
if ((int)response.StatusCode == 429)
{
return GenerateErrorTweet("Too many requests. Please refresh in a few minutes.");
}
if (response.StatusCode == HttpStatusCode.Unauthorized)
{
return GenerateErrorTweet("The keys provided have been revoked or deleted.");
}
}
throw;
}
}
示例2: SearchAsync
/// <summary>
/// Searches Twitter with the the specified query.
/// </summary>
/// <param name="query">The query.</param>
/// <param name="tokens">The tokens. Leave null for unauthenticated request.</param>
/// <param name="options">The options. Leave null for defaults.</param>
/// <returns>
/// A <see cref="TwitterSearchResultCollection"/> instance.
/// </returns>
public static async Task<TwitterResponse<TwitterSearchResultCollection>> SearchAsync(string query, OAuthTokens tokens = null, SearchOptions options = null)
{
if (options == null)
options = new SearchOptions();
return await Core.CommandPerformer.PerformAction(new Twitterizer.Commands.SearchCommand(tokens, query, options));
}
示例3: SearchAsync
public async Task<IEnumerable<TwitterSchema>> SearchAsync(string hashTag, OAuthTokens tokens)
{
try
{
var uri = new Uri(string.Format("https://api.twitter.com/1.1/search/tweets.json?q={0}", Uri.EscapeDataString(hashTag)));
var rawResult = await _request.ExecuteAsync(uri, tokens);
var result = JsonConvert.DeserializeObject<TwitterSearchResult>(rawResult);
return result.statuses
.Select(r => new TwitterSchema(r))
.ToList();
}
catch (WebException wex)
{
HttpWebResponse response = wex.Response as HttpWebResponse;
if (response != null)
{
if ((int)response.StatusCode == 429)
{
return GenerateErrorTweet("Too many requests. Please refresh in a few minutes.");
}
if (response.StatusCode == HttpStatusCode.Unauthorized)
{
return GenerateErrorTweet("The keys provided have been revoked or deleted.");
}
}
throw;
}
}
示例4: MentionsCommand
/// <summary>
/// Initializes a new instance of the <see cref="MentionsCommand"/> class.
/// </summary>
/// <param name="tokens">The request tokens.</param>
/// <param name="options">The options.</param>
public MentionsCommand(OAuthTokens tokens, TimelineOptions options)
: base(HTTPVerb.GET, "statuses/mentions_timeline.json", tokens, options)
{
if (tokens == null)
{
throw new ArgumentNullException("tokens");
}
}
示例5: HomeTimelineCommand
/// <summary>
/// Initializes a new instance of the <see cref="HomeTimelineCommand"/> class.
/// </summary>
/// <param name="tokens">The request tokens.</param>
/// <param name="optionalProperties">The optional properties.</param>
public HomeTimelineCommand(OAuthTokens tokens, TimelineOptions optionalProperties)
: base(HTTPVerb.GET, "statuses/home_timeline.json", tokens, optionalProperties)
{
if (tokens == null)
{
throw new ArgumentNullException("tokens");
}
}
示例6: authTwitter
public OAuthTokens authTwitter(string ConsumerKey, string ConsumerSecret, string AccessToken, string AccessTokenSecret)
{
OAuthTokens tokens = new OAuthTokens();
tokens.ConsumerKey = ConsumerKey;
tokens.ConsumerSecret= ConsumerSecret;
tokens.AccessToken = AccessToken;
tokens.AccessTokenSecret=AccessTokenSecret;
return tokens;
}
示例7: ExecuteAsync
public async Task<string> ExecuteAsync(Uri requestUri, OAuthTokens tokens)
{
var request = CreateRequest(requestUri, tokens);
var response = await request.GetResponseAsync();
using (StreamReader sr = new StreamReader(response.GetResponseStream()))
{
return sr.ReadToEnd();
}
}
示例8: TwitterStreaming
public TwitterStreaming(OAuthTokens Tokens, string TwitterAccount, Decimal TwitterAccountID)
{
this.TwitterAccount = TwitterAccount;
this.TwitterAccountID = TwitterAccountID;
this.Stream = new Stream(Tokens, string.Format("MetroTwit/{0}", (object) ((object) System.Windows.Application.ResourceAssembly.GetName().Version).ToString()), (StreamOptions) new UserStreamOptions()
{
AllReplies = App.AppState.Accounts[this.TwitterAccountID].Settings.AllReplies
});
this.Stopped = true;
this.StartStream();
}
示例9: CreateRequest
private static WebRequest CreateRequest(Uri requestUri, OAuthTokens tokens)
{
var requestBuilder = new OAuthRequestBuilder(requestUri, tokens);
var request = (HttpWebRequest)WebRequest.Create(requestBuilder.EncodedRequestUri);
request.UseDefaultCredentials = true;
request.Method = OAuthRequestBuilder.Verb;
request.Headers["Authorization"] = requestBuilder.AuthorizationHeader;
return request;
}
示例10: Search
/// <summary>
/// Searches Twitter with the the specified query.
/// </summary>
/// <param name="tokens">The tokens.</param>
/// <param name="query">The query.</param>
/// <param name="options">The options.</param>
/// <returns>
/// A <see cref="TwitterSearchResultCollection"/> instance.
/// </returns>
public static TwitterResponse<TwitterSearchResultCollection> Search(OAuthTokens tokens, string query, SearchOptions options)
{
if (options == null)
options = new SearchOptions();
Commands.SearchCommand command = new Twitterizer.Commands.SearchCommand(tokens, query, options);
TwitterResponse<TwitterSearchResultCollection> results =
Core.CommandPerformer.PerformAction(command);
return results;
}
示例11: sendTweet
public string sendTweet(string tweet, OAuthTokens tokens)
{
StatusUpdateOptions options = new StatusUpdateOptions() { UseSSL = true, APIBaseAddress = "http://api.twitter.com/1.1/" };
TwitterResponse<TwitterStatus> response = TwitterStatus.Update(tokens, tweet, options);
if (response.Result == RequestResult.Success)
{
return "bueno ";
}
else
{
return "malo ";
}
}
示例12: UserTimelineCommand
/// <summary>
/// Initializes a new instance of the <see cref="UserTimelineCommand"/> class.
/// </summary>
/// <param name="tokens">The request tokens.</param>
/// <param name="options">The options.</param>
public UserTimelineCommand(OAuthTokens tokens, UserTimelineOptions options)
: base(HTTPVerb.GET, "statuses/user_timeline.json", tokens, options)
{
if (tokens == null && options == null)
{
throw new ArgumentException("You must supply either OAuth tokens or identify a user in the TimelineOptions class.");
}
if (options != null && tokens == null && string.IsNullOrEmpty(options.ScreenName) && options.UserId <= 0)
{
throw new ArgumentException("You must specify a user's screen name or id for unauthorized requests.");
}
}
示例13: OAuthRequestBuilder
public OAuthRequestBuilder(Uri requestUri, OAuthTokens tokens)
{
RequestUriWithoutQuery = new Uri(requestUri.AbsoluteWithoutQuery());
QueryParams = requestUri.GetQueryParams()
.Select(p => new OAuthParameter(p.Key, p.Value))
.ToList();
EncodedRequestUri = GetEncodedUri(requestUri, QueryParams);
Version = new OAuthParameter("oauth_version", "1.0");
Nonce = new OAuthParameter("oauth_nonce", GenerateNonce());
Timestamp = new OAuthParameter("oauth_timestamp", GenerateTimeStamp());
SignatureMethod = new OAuthParameter("oauth_signature_method", "HMAC-SHA1");
ConsumerKey = new OAuthParameter("oauth_consumer_key", tokens["ConsumerKey"]);
ConsumerSecret = new OAuthParameter("oauth_consumer_secret", tokens["ConsumerSecret"]);
Token = new OAuthParameter("oauth_token", tokens["AccessToken"]);
TokenSecret = new OAuthParameter("oauth_token_secret", tokens["AccessTokenSecret"]);
}
示例14: ReportUser
/// <summary>
/// Blocks the user and reports them for spam/abuse.
/// </summary>
/// <param name="tokens">The tokens.</param>
/// <param name="screenName">The user's screen name.</param>
/// <returns>The user details.</returns>
public static TwitterResponse<TwitterUser> ReportUser(OAuthTokens tokens, string screenName)
{
return ReportUser(tokens, screenName);
}
示例15: ShowAsync
/// <include file='TwitterUser.xml' path='TwitterUser/Show[@name="Common"]/*'/>
/// <include file='TwitterUser.xml' path='TwitterUser/Show[@name="ByIDWithTokensAndOptions"]/*'/>
public static async Task<TwitterResponse<User>> ShowAsync(decimal id, OAuthTokens tokens = null, OptionalProperties options = null)
{
return await Core.CommandPerformer.PerformAction(new Commands.ShowUserCommand(tokens, id, string.Empty, options));
}