本文整理汇总了C#中LinqToTwitter.TwitterContext.TweetAsync方法的典型用法代码示例。如果您正苦于以下问题:C# TwitterContext.TweetAsync方法的具体用法?C# TwitterContext.TweetAsync怎么用?C# TwitterContext.TweetAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LinqToTwitter.TwitterContext
的用法示例。
在下文中一共展示了TwitterContext.TweetAsync方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SendTweetWithSinglePicture
static async void SendTweetWithSinglePicture()
{
var auth = new SingleUserAuthorizer
{
CredentialStore = new SingleUserInMemoryCredentialStore
{
ConsumerKey = "your consumer key",
ConsumerSecret = "your consumer secret",
AccessToken = "your access token",
AccessTokenSecret = "your access token secret"
}
};
var context = new TwitterContext(auth);
var uploadedMedia = await context.UploadMediaAsync(File.ReadAllBytes(@"c:\path\to\image.jpg"));
var mediaIds = new List<ulong> { uploadedMedia.MediaID };
await context.TweetAsync(
"Hello World! I am testing @dougvdotcom's #LinqToTwitter demo, at " +
"https://www.dougv.com/2015/08/posting-twitter-status-updates-tweets-with-linqtotwitter-and-net-part-3-media-tweets",
mediaIds
);
}
示例2: PostTwitter
public static async void PostTwitter()
{
string pl;
//var auth = AuthorizeTwitter();
var auth = AuthorizeTwitterWithToken();
var ctx = new TwitterContext(auth);
//var new Media
// {
// Data = Utilities.GetFileBytes(replaceThisWithYourImageLocation),
// FileName = "200xColor_2.png",
// ContentType = MediaContentType.Png
// };
//await ctx.TweetWithMediaAsync("Testing from Application. Posting Image", false, ReadImageFile(Path.GetFullPath("image.png")));
await ctx.TweetAsync("Testing from Application. Second Tweet!");
//var twitterCtx = new TwitterContext(auth);
await TwitterParameters(auth);
}
示例3: TweetButton_Click
async void TweetButton_Click(object sender, RoutedEventArgs e)
{
var twitterCtx = new TwitterContext(SharedState.Authorizer);
Status tweet = await twitterCtx.TweetAsync(TweetTextBox.Text);
await new MessageDialog(tweet.Text, "Tweet Sent").ShowAsync();
}
示例4: SendTweet
public static async void SendTweet(MvcAuthorizer auth, string message)
{
var ctx = new TwitterContext(auth);
var context = new TwitterContext(auth);
await context.TweetAsync(
message
);
}
示例5: ReTweet
public static async void ReTweet(MvcAuthorizer auth, int ID)
{
var ctx = new TwitterContext(auth);
var context = new TwitterContext(auth);
await context.TweetAsync(
ID.ToString()
);
}
示例6: AsyncMain
static async Task AsyncMain()
{
// Get repositories
string[] repos = ConfigurationManager.AppSettings["Repositories"]
.Split(new [] { ',' }, StringSplitOptions.RemoveEmptyEntries)
.Select(x => x.Trim())
.ToArray();
// Get excluded users
string[] excludedUsers = ConfigurationManager.AppSettings["ExcludedUsers"]
.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
.Select(x => x.Trim())
.ToArray();
// Authorize to GitHub
string token = ConfigurationManager.AppSettings["GitHubToken"];
GitHubClient github = new GitHubClient(new ProductHeaderValue("IssueTweeter"))
{
Credentials = new Credentials(token)
};
// Get issues for each repo
DateTimeOffset since = DateTimeOffset.UtcNow.AddHours(-1);
List<Task<List<KeyValuePair<string, string>>>> issuesTasks = repos.Select(x => GetIssues(github, x, since, excludedUsers)).ToList();
await Task.WhenAll(issuesTasks);
// Authorize to Twitter
SingleUserAuthorizer twitterAuth = new SingleUserAuthorizer
{
CredentialStore = new SingleUserInMemoryCredentialStore
{
ConsumerKey = ConfigurationManager.AppSettings["TwitterConsumerKey"],
ConsumerSecret = ConfigurationManager.AppSettings["TwitterConsumerSecret"],
AccessToken = ConfigurationManager.AppSettings["TwitterAccessToken"],
AccessTokenSecret = ConfigurationManager.AppSettings["TwitterAccessTokenSecret"]
}
};
TwitterContext twitterContext = new TwitterContext(twitterAuth);
// Get recent tweets
string twitterUser = ConfigurationManager.AppSettings["TwitterUser"];
List<Status> timeline = await twitterContext.Status
.Where(x => x.Type == StatusType.User && x.ScreenName == twitterUser && x.Count == 200)
.ToListAsync();
// Aggregate and eliminate issues already tweeted
List<string> tweets = issuesTasks
.SelectMany(x => x.Result.Where(i => !timeline.Any(t => t.Text.Contains(i.Key))).Select(i => i.Value))
.ToList();
// Send tweets
List<Task<Status>> tweetTasks = tweets.Select(x => twitterContext.TweetAsync(x)).ToList();
await Task.WhenAll(tweetTasks);
}
示例7: PostUpdateButton_Click
protected async void PostUpdateButton_Click(object sender, EventArgs e)
{
var auth = new AspNetAuthorizer
{
CredentialStore = new SessionStateCredentialStore(),
GoToTwitterAuthorization = twitterUrl => { }
};
var ctx = new TwitterContext(auth);
await ctx.TweetAsync(UpdateTextBox.Text);
SuccessLabel.Visible = true;
}
示例8: TweetAsync
public async Task<bool> TweetAsync(string content)
{
var tweetContent = CheckContent(content);
try
{
using (var context = new TwitterContext(_selfAuthorizer))
{
await context.TweetAsync(content);
return true;
}
}
catch (TwitterQueryException ex) when (ex.StatusCode == HttpStatusCode.Forbidden) // In case of duplicate
{
return false;
}
}
示例9: nouveauTweetBouton_Click
private void nouveauTweetBouton_Click(object sender, EventArgs e)
{
var twitterContext = new TwitterContext(authorizer);
nouveauTweetFenetre nt = new nouveauTweetFenetre();
if (nt.ShowDialog() == DialogResult.OK)
{
if (nt.Tweet.Length > 0)
{
twitterContext.TweetAsync(nt.Tweet);
MessageBox.Show("Le tweet est publié");
}
recupererTweets();
}
}
示例10: Main
static void Main(string[] args)
{
Task.Run(async () =>
{
AppSettingsReader cfgReader = new AppSettingsReader();
string _UseProxy = cfgReader.GetValue("UseProxy", typeof(string)).ToString();
var auth = new SingleUserAuthorizer
{
CredentialStore = new SingleUserInMemoryCredentialStore
{
ConsumerKey = cfgReader.GetValue("ConsumerKey", typeof(string)).ToString(),
ConsumerSecret = cfgReader.GetValue("ConsumerSecret", typeof(string)).ToString(),
AccessToken = cfgReader.GetValue("AccessToken", typeof(string)).ToString(),
AccessTokenSecret = cfgReader.GetValue("AccessSecret", typeof(string)).ToString()
}
};
if (_UseProxy.Equals("1"))
{
auth.Proxy = new WebProxy(cfgReader.GetValue("ProxyAddress", typeof(string)).ToString());
auth.Proxy.Credentials = new NetworkCredential(
cfgReader.GetValue("ProxyUser", typeof(string)).ToString(),
cfgReader.GetValue("ProxyPass", typeof(string)).ToString());
}
var twitterContext = new TwitterContext(auth);
string _teste = "Tweet sent via LinqToTwitter";
var tweet = await twitterContext.TweetAsync(_teste);
if (tweet != null)
{
Console.WriteLine("Status: {0}", tweet.StatusID.ToString());
}
}).Wait();
Console.ReadLine();
}
示例11: TweetAsync
public async Task<ActionResult> TweetAsync(SendTweetViewModel tweet)
{
var auth = new MvcAuthorizer
{
CredentialStore = new SessionStateCredentialStore()
};
var ctx = new TwitterContext(auth);
Status responseTweet = await ctx.TweetAsync(tweet.Text);
var responseTweetVM = new SendTweetViewModel
{
Text = "Testing async LINQ to Twitter in MVC - " + DateTime.Now.ToString(),
Response = "Tweet successful! Response from Twitter: " + responseTweet.Text
};
return View(responseTweetVM);
}
示例12: TweetButton_Click
async void TweetButton_Click(object sender, RoutedEventArgs e)
{
IAuthorizer auth = SharedState.Authorizer;
var twitterCtx = new TwitterContext(auth);
decimal latitude = 37.78215m;
decimal longitude = -122.40060m;
Status tweet = await twitterCtx.TweetAsync(TweetTextBox.Text, latitude, longitude);
MessageBox.Show(
"User: " + tweet.User.ScreenNameResponse +
", Posted Status: " + tweet.Text,
"Update Successfully Posted.",
MessageBoxButton.OK);
TweetTextBox.Text = "Windows Phone Test, " + DateTime.Now.ToString() + " #linq2twitter";
}
示例13: SendTweet
static async void SendTweet()
{
var auth = new SingleUserAuthorizer
{
CredentialStore = new SingleUserInMemoryCredentialStore
{
ConsumerKey = "your consumer key",
ConsumerSecret = "your consumer secret",
AccessToken = "your access token",
AccessTokenSecret = "your access token secret"
}
};
var context = new TwitterContext(auth);
await context.TweetAsync(
"Hello World! I am testing @dougvdotcom's #LinqToTwitter demo, at " +
"https://www.dougv.com/2015/08/posting-status-updates-to-twitter-via-linqtotwitter-part-2-plain-text-tweets"
);
}
示例14: TweetButton_Click
private async void TweetButton_Click(object sender, RoutedEventArgs e)
{
var authorizer = new UniversalAuthorizer
{
CredentialStore = new InMemoryCredentialStore
{
ConsumerKey = "",
ConsumerSecret = ""
}
};
await authorizer.AuthorizeAsync();
var ctx = new TwitterContext(authorizer);
string userInput = tweetText.Text;
Status tweet = await ctx.TweetAsync(userInput);
ResponseTextBlock.Text = tweet.Text;
await new MessageDialog("You Tweeted: " + tweet.Text, "Success!").ShowAsync();
}
示例15: PostTweet
public async Task<ActionResult> PostTweet(string tweetText = "")
{
MvcAuthorizer auth = new MvcAuthorizer
{
CredentialStore = new SessionStateCredentialStore()
};
// do OAuth if the token is null
if (auth.CredentialStore.OAuthToken == null)
{
return RedirectToAction("BeginAsync", "OAuth", new { returnUrl = Request.Url });
}
Status postedTweet;
ulong postedTweetStatusId = 0;
if (!string.IsNullOrEmpty(tweetText))
{
var twitterCtx = new TwitterContext(auth);
postedTweet = await twitterCtx.TweetAsync(tweetText);
postedTweetStatusId = postedTweet.StatusID;
}
else
{
postedTweet = null;
}
var viewModel = new PostTweetViewModel()
{
TweetText = tweetText,
PostedTweet = postedTweet,
PostedTweetStatusId = postedTweetStatusId
};
return View(viewModel);
}