当前位置: 首页>>代码示例>>C#>>正文


C# TwitterContext.UploadMediaAsync方法代码示例

本文整理汇总了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
            );
        }
开发者ID:dougvdotcom,项目名称:linqtotwitter_demo,代码行数:24,代码来源:Program.cs

示例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);
        }
开发者ID:yaremado,项目名称:LinqToTwitter,代码行数:13,代码来源:StatusDemos.cs

示例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);
        }
开发者ID:yaremado,项目名称:LinqToTwitter,代码行数:27,代码来源:StatusDemos.cs

示例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);
        }
开发者ID:prog-moh,项目名称:LinqToTwitter,代码行数:32,代码来源:AccountDemos.cs

示例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
            );
        }
开发者ID:dougvdotcom,项目名称:linqtotwitter_demo,代码行数:34,代码来源:Program.cs


注:本文中的LinqToTwitter.TwitterContext.UploadMediaAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。