示例#1
0
        public static async Task <CommentListResponse> ExecuteAllAsync(this CommentsResource.ListRequest request, CancellationToken ct = default(CancellationToken))
        {
            request.MaxResults = request.MaxResults ?? 100;
            var response = await request.ExecuteAsync(ct);

            if (!response.Items.Any())
            {
                return(response);
            }
            var collection = response.Items.ToList();

            while (!ct.IsCancellationRequested)
            {
                if (string.IsNullOrWhiteSpace(response.NextPageToken))
                {
                    break;
                }
                request.PageToken = response.NextPageToken;
                response          = await request.ExecuteAsync(ct);

                if (response.Items.Any())
                {
                    collection.AddRange(response.Items);
                }
            }

            response.Items = collection;
            return(response);
        }
示例#2
0
        public static CommentList getComments(BloggerService service, BlogLink blogLink, String postId)
        {
            CommentsResource.ListRequest commentsListRequest = null;
            try
            {
                commentsListRequest = new CommentsResource.ListRequest(service, blogLink.blogId, postId);
            }
            catch (Exception ex)
            {
                DAL.InsertAccessLog(blogLink.blogName, blogLink.userId, ex.ToString());
            }

            return(commentsListRequest.Fetch());
        }
        public static IList<Comment> GetAllCommentsPaging(PlusService service, string _activityId, int NumberOfPages, int ItemsPerPage, string NextPageToken)
        {
            //List all of the activities in the specified collection for the current user.  
            // Documentation: https://developers.google.com/+/api/latest/activities/list
            int count = 0;
            int iterate = NumberOfPages;
            CommentsResource.ListRequest listComments = service.Comments.List(_activityId);


            listComments.MaxResults = ItemsPerPage;

            CommentFeed commentsFeed = listComments.Execute();
            count++;
            IList<Comment> Comments = new List<Comment>();



            //// Loop through until we arrive at an empty page
            while (commentsFeed.Items != null || count <= iterate)
            {
                // Prepare the next page of results
                listComments.PageToken = commentsFeed.NextPageToken;


                // Adding each item  to the list.
                foreach (Comment item in commentsFeed.Items)
                {
                    Comments.Add(item);
                }

                // We will know we are on the last page when the next page token is
                // null.
                // If this is the case, break.
                if (commentsFeed.NextPageToken == null || count >= iterate)
                {
                    break;
                }


                // Execute and process the next page request
                commentsFeed = listComments.Execute();
                count++;
            }
            Comment token = new Comment();
            token.Id = commentsFeed.NextPageToken;
            Comments.Add(token);
            return Comments;
        }
        /// <summary>
        /// List all of the comments for an activity.
        /// Documentation:  https://developers.google.com/+/api/latest/comments/list
        /// </summary>
        /// <param name="service">a Valid authenticated PlusService</param>
        /// <param name="_activityId">The ID of the activity to get comments for.</param>
        /// <returns></returns>
        public static IList <Comment> GetAllComments(PlusService service, string _activityId)
        {
            //List all of the activities in the specified collection for the current user.
            // Documentation: https://developers.google.com/+/api/latest/activities/list
            CommentsResource.ListRequest listComments = service.Comments.List(_activityId);


            listComments.MaxResults = 100;
            CommentFeed     commentsFeed = listComments.Execute();
            IList <Comment> Comments     = new List <Comment>();



            //// Loop through until we arrive at an empty page
            while (commentsFeed.Items != null)
            {
                // Adding each item  to the list.
                foreach (Comment item in commentsFeed.Items)
                {
                    Comments.Add(item);
                }

                // We will know we are on the last page when the next page token is
                // null.
                // If this is the case, break.
                if (commentsFeed.NextPageToken == null)
                {
                    break;
                }

                // Prepare the next page of results
                listComments.PageToken = commentsFeed.NextPageToken;

                // Execute and process the next page request
                commentsFeed = listComments.Execute();
            }

            return(Comments);
        }
        /// <summary>
        /// Gets the comments for the specified comment thread.
        /// </summary>
        /// <param name="commentThread">The comment thread to get comments for</param>
        /// <param name="maxResults">The maximum results to return</param>
        /// <returns>The list of comments</returns>
        public async Task <IEnumerable <Comment> > GetCommentsForCommentThread(CommentThread commentThread, int maxResults = 1)
        {
            Validator.ValidateVariable(commentThread, "commentThread");
            return(await this.YouTubeServiceWrapper(async() =>
            {
                List <Comment> results = new List <Comment>();
                string pageToken = null;
                do
                {
                    CommentsResource.ListRequest request = this.connection.GoogleYouTubeService.Comments.List("snippet");
                    request.ParentId = commentThread.Id;
                    request.MaxResults = Math.Min(maxResults, 50);
                    request.PageToken = pageToken;

                    CommentListResponse response = await request.ExecuteAsync();
                    results.AddRange(response.Items);
                    maxResults -= response.Items.Count;
                    pageToken = response.NextPageToken;
                } while (maxResults > 0 && !string.IsNullOrEmpty(pageToken));
                return results;
            }));
        }