コード例 #1
0
        private void button5_Click(object sender, EventArgs e)
        {
            scopes = new string[] { PlusService.Scope.PlusLogin,
                                    PlusService.Scope.UserinfoEmail,
                                    PlusService.Scope.UserinfoProfile };
            // here is where we Request the user to give us access, or use the Refresh Token that was previously stored in %AppData%
            UserCredential credential =
                GoogleWebAuthorizationBroker.AuthorizeAsync(new ClientSecrets
            {
                ClientId     = client_id,
                ClientSecret = client_secret
            },
                                                            scopes,
                                                            Environment.UserName,
                                                            CancellationToken.None,
                                                            new FileDataStore("Daimto.GooglePlus.Auth.Store")
                                                            ).Result;


            service = new Google.Apis.Plus.v1.PlusService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential,
                ApplicationName       = "Google Plus Sample",
            });


            ActivitiesResource.SearchRequest list = service.Activities.Search(q);
        }
コード例 #2
0
        public static IList<Activity> SearchActivitiesPaging(PlusService service, string _query, 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
            ActivitiesResource.SearchRequest list = service.Activities.Search(_query);
            int max = ItemsPerPage;
            int iterate = NumberOfPages;
            list.PageToken = NextPageToken;
            list.MaxResults = max;
            int count = 0;
            ActivityFeed activitesFeed = list.Execute();
            IList<Activity> Activites = new List<Activity>();
            count++;
            //// Loop through until we arrive at an empty page
            while (activitesFeed.Items != null || count <= iterate)
            {
                // Prepare the next page of results
                list.PageToken = activitesFeed.NextPageToken;

                // Adding each item  to the list.
                foreach (Activity item in activitesFeed.Items)
                {
                    Activites.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 (activitesFeed.NextPageToken == null || count >= iterate)
                {
                    break;
                }


                // Execute and process the next page request
                activitesFeed = list.Execute();
                count++;
            }
            Activity token = new Activity();
            token.Title = activitesFeed.NextPageToken;
            Activites.Add(token);
            return Activites;
        }
コード例 #3
0
        /// <summary>
        /// Search public activities.
        /// 
        /// Documentation: https://developers.google.com/+/api/latest/activities/search
        /// </summary>
        /// <param name="service">a Valid authenticated PlusService</param>
        /// <param name="_query">Full-text search query string.</param>
        /// <returns></returns>
        public static IList<Activity> SearchActivities(PlusService service, string _query)
        {
            //List all of the activities in the specified collection for the current user.  
            // Documentation: https://developers.google.com/+/api/latest/activities/list
            ActivitiesResource.SearchRequest list = service.Activities.Search(_query);
            list.MaxResults = 20;
            ActivityFeed activitesFeed = list.Execute();
            IList<Activity> Activites = new List<Activity>();
            int Count = 0;
            //// Loop through until we arrive at an empty page
            while (activitesFeed.Items != null)
            {
                // Adding each item  to the list.
                foreach (Activity item in activitesFeed.Items)
                {
                    Activites.Add(item);
                    Count++;
                }

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

                // Prepare the next page of results
                list.PageToken = activitesFeed.NextPageToken;

                // Execute and process the next page request
                activitesFeed = list.Execute();

            }

            return Activites;
        }