コード例 #1
0
        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;
        }
コード例 #2
0
        /// <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);
        }