本文整理汇总了C#中LinqToTwitter.TwitterContext.UploadMediaAsync方法的典型用法代码示例。如果您正苦于以下问题:C# TwitterContext.UploadMediaAsync方法的具体用法?C# TwitterContext.UploadMediaAsync怎么用?C# TwitterContext.UploadMediaAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LinqToTwitter.TwitterContext
的用法示例。
在下文中一共展示了TwitterContext.UploadMediaAsync方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: UploadVideoAsync
static async Task UploadVideoAsync(TwitterContext twitterCtx)
{
string status =
"Testing video upload tweet #Linq2Twitter £ " +
DateTime.Now.ToString(CultureInfo.InvariantCulture);
Media media = await twitterCtx.UploadMediaAsync(File.ReadAllBytes(@"..\..\images\SampleVideo.mp4"), "video/mp4");
Status tweet = await twitterCtx.TweetAsync(status, new ulong[] { media.MediaID });
if (tweet != null)
Console.WriteLine("Tweet sent: " + tweet.Text);
}
示例3: UploadMultipleImagesAsync
static async Task UploadMultipleImagesAsync(TwitterContext twitterCtx)
{
var additionalOwners = new List<ulong> { 3265644348, 15411837 };
string status =
"Testing multi-image tweet #Linq2Twitter £ " +
DateTime.Now.ToString(CultureInfo.InvariantCulture);
var imageUploadTasks =
new List<Task<Media>>
{
twitterCtx.UploadMediaAsync(File.ReadAllBytes(@"..\..\images\200xColor_2.png"), "image/png", additionalOwners),
twitterCtx.UploadMediaAsync(File.ReadAllBytes(@"..\..\images\WP_000003.jpg"), "image/jpg"),
twitterCtx.UploadMediaAsync(File.ReadAllBytes(@"..\..\images\13903749474_86bd1290de_o.jpg"), "image/jpg"),
};
await Task.WhenAll(imageUploadTasks);
List<ulong> mediaIds =
(from tsk in imageUploadTasks
select tsk.Result.MediaID)
.ToList();
Status tweet = await twitterCtx.TweetAsync(status, mediaIds);
if (tweet != null)
Console.WriteLine("Tweet sent: " + tweet.Text);
}
示例4: UpdateAccountBackgroundImageAsync
static async Task UpdateAccountBackgroundImageAsync(TwitterContext twitterCtx)
{
byte[] imageBytes = File.ReadAllBytes(@"..\..\Images\200xColor_2.png");
string mediaType = "image/png";
//// one way is to pass the byte[]
//var user1 =
// await twitterCtx.UpdateAccountBackgroundImageAsync(
// image: imageBytes,
// fileName: "LinqToTwitterLogo1.jpg",
// imageType: "png",
// tile: false,
// includeEntities: false,
// skipStatus: true);
// another way is to upload the media and pass a media ID
Media media = await twitterCtx.UploadMediaAsync(imageBytes, mediaType);
var user2 =
await twitterCtx.UpdateAccountBackgroundImageAsync(
media.MediaID,
fileName: "LinqToTwitterLogo2.png",
imageType: "png",
tile: false,
includeEntities: false,
skipStatus: true);
//if (user1 != null)
// Console.WriteLine("User1 Image: " + user1.ProfileImageUrl);
if (user2 != null)
Console.WriteLine("User2 Image: " + user2.ProfileImageUrl);
}
示例5: SendTweetWithMultiplePictures
static async void SendTweetWithMultiplePictures()
{
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 imageUploadTasks =
new List<Task<Media>>
{
context.UploadMediaAsync(File.ReadAllBytes(@"c:\path\to\image1.jpg")),
context.UploadMediaAsync(File.ReadAllBytes(@"c:\path\to\image2.png")),
context.UploadMediaAsync(File.ReadAllBytes(@"c:\path\to\image3.jpg"))
};
await Task.WhenAll(imageUploadTasks);
var mediaIds =
(from tsk in imageUploadTasks
select tsk.Result.MediaID)
.ToList();
await context.TweetAsync(
"Photos of Acadia National Park by Kim Seng https://www.flickr.com/photos/captainkimo/ #LinqToTwitter",
mediaIds
);
}