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


C# TwitterContext.AddSiteStreamUserAsync方法代码示例

本文整理汇总了C#中LinqToTwitter.TwitterContext.AddSiteStreamUserAsync方法的典型用法代码示例。如果您正苦于以下问题:C# TwitterContext.AddSiteStreamUserAsync方法的具体用法?C# TwitterContext.AddSiteStreamUserAsync怎么用?C# TwitterContext.AddSiteStreamUserAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在LinqToTwitter.TwitterContext的用法示例。


在下文中一共展示了TwitterContext.AddSiteStreamUserAsync方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DoControlStreamAsync

        static async Task DoControlStreamAsync(TwitterContext twitterCtx)
        {
            var evt = new ManualResetEventSlim(false);
            string streamID = string.Empty;

            Task.Run(async () =>
            {
                Console.WriteLine("\nStreamed Content: \n");
                int count = 0;
                var cancelTokenSrc = new CancellationTokenSource();

                try
                {
                    await
                        (from strm in twitterCtx.Streaming
                         where strm.Type == StreamingType.Site &&
                               strm.Follow == "15411837,16761255"
                         select strm)
                        .WithCancellation(cancelTokenSrc.Token)
                        .StartAsync(async strm =>
                        {
                            if (string.IsNullOrEmpty(strm.Content))
                                Console.WriteLine("Keep-Alive");
                            else
                                HandleStreamResponse(strm);

                            if (strm.EntityType == StreamEntityType.Control)
                            {
                                var control = strm.Entity as Control;
                                streamID = control.URL.Replace("/1.1/site/c/", "");
                                evt.Set();
                            }

                            if (count++ == 25)
                                cancelTokenSrc.Cancel();
                        });
                }
                catch (OperationCanceledException)
                {
                    Console.WriteLine("Stream cancelled.");
                }
            });

            evt.Wait();

            Console.WriteLine("Follower Details:\n");

            var ctrlStrmFollowers =
                await
                (from strm in twitterCtx.ControlStream
                    where strm.Type == ControlStreamType.Followers &&
                        strm.UserID == 15411837 &&
                        strm.StreamID == streamID
                    select strm)
                .SingleOrDefaultAsync();

            if (ctrlStrmFollowers != null)
            {
                ControlStreamFollow follow = ctrlStrmFollowers.Follow;
                ControlStreamUser followUser = follow.User;
                List<ulong> friends = follow.Friends;
                Cursors cursors = follow.Cursors;

                Console.WriteLine("User ID: " + followUser.UserID);
                Console.WriteLine("User Name: " + followUser.Name);
                Console.WriteLine("Can DM: " + followUser.DM);
                friends.ForEach(friend => Console.WriteLine(friend));
                Console.WriteLine("Prev Cursor: " + cursors.Previous);
                Console.WriteLine("Next Cursor: " + cursors.Next);

                Console.WriteLine("Info Details:\n");
            } 
            
            var ctrlStrmInfo =
                (from strm in twitterCtx.ControlStream
                    where strm.Type == ControlStreamType.Info &&
                        strm.StreamID == streamID
                    select strm)
                .SingleOrDefault();

            if (ctrlStrmInfo != null)
            {
                ControlStreamInfo infoUser = ctrlStrmInfo.Info;
                ControlStreamUser user = infoUser.Users.First();
                Console.WriteLine("User ID: " + user.UserID);
                Console.WriteLine("User Name: " + user.Name);
                Console.WriteLine("Can DM: " + user.DM);
                Console.WriteLine("Delimited: " + infoUser.Delimited);
                Console.WriteLine("Include Followings Acitity: " + infoUser.IncludeFollowingsActivity);
                Console.WriteLine("Include User Changes: " + infoUser.IncludeUserChanges);
                Console.WriteLine("Replies: " + infoUser.Replies);
                Console.WriteLine("With: " + infoUser.With);

                Console.WriteLine("\nInitial Stream Users: ");

                await PrintUserInfoAsync(twitterCtx, streamID);

                ControlStream csAdd = await twitterCtx.AddSiteStreamUserAsync(new List<ulong> { 16761255 }, streamID);
                Console.WriteLine("Command Response: " + csAdd.CommandResponse);
                Console.WriteLine("\nAfter Adding a User: ");
//.........这里部分代码省略.........
开发者ID:prog-moh,项目名称:LinqToTwitter,代码行数:101,代码来源:StreamDemos.cs


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