本文整理汇总了C#中TweetSharp.TwitterService.AuthenticateWith方法的典型用法代码示例。如果您正苦于以下问题:C# TwitterService.AuthenticateWith方法的具体用法?C# TwitterService.AuthenticateWith怎么用?C# TwitterService.AuthenticateWith使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TweetSharp.TwitterService
的用法示例。
在下文中一共展示了TwitterService.AuthenticateWith方法的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: Search
public SearchResultWithRateLimit Search(string queryTerm, int resultType, long sinceId, TwitterApp keys)
{
SearchOptions options = new SearchOptions
{
Q = System.Web.HttpUtility.UrlEncode(queryTerm),
Count = 100,
Lang = "en",
Resulttype = (TwitterSearchResultType)resultType,
SinceId = sinceId
};
var service = new TwitterService(keys.ConsumerKey, keys.ConsumerKeySecret);
service.AuthenticateWith(keys.Token, keys.TokenSecret);
var result = new SearchResultWithRateLimit();
result.SearchResult = service.Search(options);
result.RateLimitStatus = service.Response.RateLimitStatus;
if (result.SearchResult.Statuses.Any())
{
result.LastId = result.SearchResult.Statuses.OrderByDescending(f => f.Id).FirstOrDefault().Id;
}
else
{
result.LastId = options.SinceId.Value;
}
return result;
}
示例3: Tweeter
public Tweeter()
{
var _consumerKey = "J9iaXHK7R0bpKiRabxQ";
var _consumerSecret = "Xs6XJggEvXtMVDvaYAvTLnIm13G70ymcdhwQ3J1M";
// this authentication snippet borrowed from https://github.com/danielcrenna/tweetsharp
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
// OAuthAccessToken access = service.GetAccessToken(requestToken, verifier);
// OAuthAccessToken generated manually through dev.twitter.com so no need for this bit since it's just me tweetin ma shit
var access = new OAuthAccessToken();
access.Token = "1196853272-YbSEB0Mnaj6lK3tOKGQ8nwOVLnfhXldwqjlzNmk";
access.TokenSecret = "4BHhe3iUdlh6o2Re0OmMq3v6e8OwH9vw149MEPR3I";
// Step 4 - User authenticates using the Access Token
service.AuthenticateWith(access.Token, access.TokenSecret);
// service.SendTweet(new SendTweetOptions { Status = "Hello World" });
}
示例4: 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;
}
}
示例5: GetAuthenticatedService
private static TwitterService GetAuthenticatedService()
{
var service = new TwitterService(_consumerKey, _consumerSecret);
service.TraceEnabled = true;
service.AuthenticateWith(_accessToken, _accessTokenSecret);
return service;
}
示例6: 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));
}
}
示例7: 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 "";
}
示例8: 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;
}
示例9: 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;
}
示例10: 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();
}
示例11: IndexModule
public IndexModule()
{
Get["/locations/{user}", true] = async (paramaters, ct) =>
{
var service = new TwitterService(ConfigurationManager.AppSettings["TWITTER_CONSUMER_KEY"], ConfigurationManager.AppSettings["TWITTER_CONSUMER_SECRET"]);
service.AuthenticateWith(ConfigurationManager.AppSettings["TWITTER_ACCESS_TOKEN"], ConfigurationManager.AppSettings["TWITTER_ACCESS_TOKEN_SECRET"]);
string user = paramaters.user.ToString();
user.Replace("#", "");
var tweets = service.ListTweetsOnUserTimeline(new ListTweetsOnUserTimelineOptions()
{
ContributorDetails = true,
Count = 100,
ExcludeReplies = false,
IncludeRts = true,
ScreenName = user
}).ToList();
var tweetsWithLocations = tweets.Where(t => t.Location != null).ToList().OrderBy(t => t.CreatedDate);
return Response.AsJson(tweetsWithLocations.Select(t => new
{
LastTweet = t.TextAsHtml,
Location = t.Location,
Date =
t.CreatedDate.ToShortDateString() + " " +
t.CreatedDate.ToShortTimeString()
})).WithHeaders(new []
{
new { Header = "Access-Control-Allow-Origin", Value="*" }
});
};
}
示例12: 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();
}
示例13: 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);
}
示例14: ApplicationBarIconButton_Click
private void ApplicationBarIconButton_Click(object sender, EventArgs e)
{
if (img_bool == true && twit_pic == "")
{
MessageBox.Show("Image upload in progress. please wait.", "Sorry", MessageBoxButton.OK);
return;
}
if (WatermarkTB.Text == emptystr)
{
MessageBox.Show("Please input your mind :)", "Sorry", MessageBoxButton.OK);
return;
}
TwitterService service = new TwitterService("g8F2KdKH40gGp9BXemw13Q", "OyFRFsI05agcJtURtLv8lpYbYRwZAIL5gr5xQNPW0Q");
service.AuthenticateWith((string)settings["twitter_token"], (string)settings["twitter_tokensecret"]);
string tweet = WatermarkTB.Text;
if (img_bool == true)
tweet += " " + twit_pic;
service.SendTweet(tweet,
(tweets, response) =>
{
});
MessageBox.Show("Share successfully.", "Thanks", MessageBoxButton.OK);
this.NavigationService.GoBack();
}
示例15: GetAuthenticatedService
public TwitterService GetAuthenticatedService()
{
var twitterClientInfo = new TwitterClientInfo {ConsumerKey = ConsumerKey, ConsumerSecret = ConsumerSecret};
twitterService = new TwitterService(twitterClientInfo);
twitterService.AuthenticateWith(AccessToken, AccessTokenSecret);
return twitterService;
}