public List<String> Search(String query, int pages=1)
        {
            BaseClientService.Initializer init = new Google.Apis.Services.BaseClientService.Initializer();
            init.ApiKey = key;
            CustomsearchService svc = new CustomsearchService(init);

            List<String> imageUrls = new List<String>();

            for (int p = 1; p <= pages; p++)
            {
                CseResource.ListRequest listRequest = svc.Cse.List(query);
                listRequest.Cx = customEngine;
                listRequest.SearchType = CseResource.SearchType.Image;
                listRequest.Start = p*10;
                listRequest.ImgColorType = CseResource.ImgColorType.Color;
                Search search = listRequest.Fetch();

                //Let's just get the thumbnail images
                if (search.Items != null)
                {
                    foreach (Result result in search.Items)
                    {
                        imageUrls.Add(result.Image.ThumbnailLink);
                    }
                }
            }
            return imageUrls;
        }
Esempio n. 2
0
 /// <summary>Constructs a new service.</summary>
 /// <param name="initializer">The service initializer.</param>
 public CloudBillingBudgetService(Google.Apis.Services.BaseClientService.Initializer initializer)
     : base(initializer)
 {
     billingAccounts = new BillingAccountsResource(this);
 }
Esempio n. 3
0
 /// <summary>Constructs a new service.</summary>
 /// <param name="initializer">The service initializer.</param>
 public FirebaseMLService(Google.Apis.Services.BaseClientService.Initializer initializer)
     : base(initializer)
 {
     operations = new OperationsResource(this);
 }
Esempio n. 4
0
 /// <summary>Constructs a new service.</summary>
 /// <param name="initializer">The service initializer.</param>
 public CloudTraceService(Google.Apis.Services.BaseClientService.Initializer initializer)
     : base(initializer)
 {
     projects = new ProjectsResource(this);
 }
Esempio n. 5
0
 /// <summary>Constructs a new service.</summary>
 /// <param name="initializer">The service initializer.</param>
 public FirebaseRemoteConfigService(Google.Apis.Services.BaseClientService.Initializer initializer)
     : base(initializer)
 {
     projects = new ProjectsResource(this);
 }
Esempio n. 6
0
 /// <summary>Constructs a new service.</summary>
 /// <param name="initializer">The service initializer.</param>
 public KgsearchService(Google.Apis.Services.BaseClientService.Initializer initializer)
     : base(initializer)
 {
     entities = new EntitiesResource(this);
 }
Esempio n. 7
0
 /// <summary>Constructs a new service.</summary>
 /// <param name="initializer">The service initializer.</param>
 public WorkflowExecutionsService(Google.Apis.Services.BaseClientService.Initializer initializer) : base(initializer)
 {
     Projects = new ProjectsResource(this);
 }
Esempio n. 8
0
 /// <summary>Constructs a new service.</summary>
 /// <param name="initializer">The service initializer.</param>
 public SiteVerificationService(Google.Apis.Services.BaseClientService.Initializer initializer)
     : base(initializer)
 {
     webResource = new WebResourceResource(this);
 }
 /// <summary>Constructs a new service.</summary>
 /// <param name="initializer">The service initializer.</param>
 public BigQueryReservationService(Google.Apis.Services.BaseClientService.Initializer initializer)
     : base(initializer)
 {
     operations = new OperationsResource(this);
 }
 /// <summary>Constructs a new service.</summary>
 /// <param name="initializer">The service initializer.</param>
 public DataTransferService(Google.Apis.Services.BaseClientService.Initializer initializer)
     : base(initializer)
 {
     applications = new ApplicationsResource(this);
     transfers    = new TransfersResource(this);
 }
Esempio n. 11
0
 /// <summary>Constructs a new service.</summary>
 /// <param name="initializer">The service initializer.</param>
 public VerifiedaccessService(Google.Apis.Services.BaseClientService.Initializer initializer)
     : base(initializer)
 {
     challenge = new ChallengeResource(this);
 }
 /// <summary>Constructs a new service.</summary>
 /// <param name="initializer">The service initializer.</param>
 public IdeahubService(Google.Apis.Services.BaseClientService.Initializer initializer) : base(initializer)
 {
     Platforms = new PlatformsResource(this);
 }
Esempio n. 13
0
 /// <summary>Constructs a new service.</summary>
 /// <param name="initializer">The service initializer.</param>
 public PagespeedonlineService(Google.Apis.Services.BaseClientService.Initializer initializer)
     : base(initializer)
 {
     pagespeedapi = new PagespeedapiResource(this);
 }
Esempio n. 14
0
 /// <summary>Constructs a new service.</summary>
 /// <param name="initializer">The service initializer.</param>
 public IAMCredentialsService(Google.Apis.Services.BaseClientService.Initializer initializer)
     : base(initializer)
 {
     projects = new ProjectsResource(this);
 }
Esempio n. 15
0
        public void CreateNewAppointment()
        {
            string gmailUsername;
            string syncProfile;
            GoogleAPITests.LoadSettings(out gmailUsername, out syncProfile);

            EventsResource service;
            CalendarListEntry primaryCalendar = null;
            var scopes = new List<string>();
            //Contacts-Scope
            scopes.Add("https://www.google.com/m8/feeds");
            //Notes-Scope
            scopes.Add("https://docs.google.com/feeds/");
            //scopes.Add("https://docs.googleusercontent.com/");
            //scopes.Add("https://spreadsheets.google.com/feeds/");
            //Calendar-Scope
            //scopes.Add("https://www.googleapis.com/auth/calendar");
            scopes.Add(CalendarService.Scope.Calendar);

            UserCredential credential;
            byte[] jsonSecrets = Properties.Resources.client_secrets;

            //using (var stream = new FileStream(Path.GetDirectoryName(System.Reflection.Assembly.GetAssembly(this.GetType()).Location) + "\\client_secrets.json", FileMode.Open, FileAccess.Read))
            //using (var stream = new FileStream("client_secrets.json", FileMode.Open, FileAccess.Read))
                    //using (var stream = new FileStream(Application.StartupPath + "\\client_secrets.json", FileMode.Open, FileAccess.Read))
            using (var stream = new MemoryStream(jsonSecrets))
            {
                FileDataStore fDS = new FileDataStore(Logger.AuthFolder, true);
                credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                GoogleClientSecrets.Load(stream).Secrets, scopes, gmailUsername, CancellationToken.None,
                fDS).Result;

                var initializer = new Google.Apis.Services.BaseClientService.Initializer();
                initializer.HttpClientInitializer = credential;
                var CalendarRequest = new CalendarService(initializer);
                //CalendarRequest.setUserCredentials(username, password);

                var list = CalendarRequest.CalendarList.List().Execute().Items;
                foreach (var calendar in list)
                {
                    if (calendar.Primary != null && calendar.Primary.Value)
                    {
                        primaryCalendar = calendar;
                        break;
                    }
                }

                if (primaryCalendar == null)
                    throw new Exception("Primary Calendar not found");

                //EventQuery query = new EventQuery("https://www.google.com/calendar/feeds/default/private/full");
                //ToDo: Upgrade to v3, EventQuery query = new EventQuery("https://www.googleapis.com/calendar/v3/calendars/default/events");
                service = CalendarRequest.Events;
            }

            #region Delete previously created test contact.
            var query = service.List(primaryCalendar.Id);
            query.MaxResults = 500;
            query.TimeMin = DateTime.Now.AddDays(-10);
            query.TimeMax = DateTime.Now.AddDays(10);
            //query.Q = "GCSM Test Appointment";

            var feed = query.Execute();
            Logger.Log("Loaded Google appointments", EventType.Information);
            foreach (Google.Apis.Calendar.v3.Data.Event entry in feed.Items)
            {
                if (entry.Summary != null && entry.Summary.Contains("GCSM Test Appointment") && !entry.Status.Equals("cancelled"))
                {
                    Logger.Log("Deleting Google appointment:" +entry.Summary + " - " + entry.Start.DateTime.ToString(), EventType.Information);
                    service.Delete(primaryCalendar.Id, entry.Id);
                    Logger.Log("Deleted Google appointment", EventType.Information);
                    //break;
                }
            }

            #endregion

            var newEntry = Factory.NewEvent();
            newEntry.Summary = "GCSM Test Appointment";
            newEntry.Start.DateTime = DateTime.Now;
            newEntry.End.DateTime = DateTime.Now;

            var createdEntry = service.Insert(newEntry,primaryCalendar.Id).Execute();

            Logger.Log("Created Google appointment", EventType.Information);

            Assert.IsNotNull(createdEntry.Id);

            var updatedEntry = service.Update(createdEntry, primaryCalendar.Id,createdEntry.Id).Execute();

            Logger.Log("Updated Google appointment", EventType.Information);

            //delete test contacts
            service.Delete(primaryCalendar.Id, updatedEntry.Id).Execute();

            Logger.Log("Deleted Google appointment", EventType.Information);
        }
Esempio n. 16
0
 /// <summary>Constructs a new service.</summary>
 /// <param name="initializer">The service initializer.</param>
 public DriveService(Google.Apis.Services.BaseClientService.Initializer initializer)
     : base(initializer)
 {
     files = new FilesResource(this);
 }
 /// <summary>Constructs a new service.</summary>
 /// <param name="initializer">The service initializer.</param>
 public SearchConsoleService(Google.Apis.Services.BaseClientService.Initializer initializer)
     : base(initializer)
 {
     urlTestingTools = new UrlTestingToolsResource(this);
 }
 /// <summary>Constructs a new service.</summary>
 /// <param name="initializer">The service initializer.</param>
 public AdExchangeBuyerService(Google.Apis.Services.BaseClientService.Initializer initializer)
     : base(initializer)
 {
     accounts  = new AccountsResource(this);
     creatives = new CreativesResource(this);
 }
 /// <summary>Constructs a new service.</summary>
 /// <param name="initializer">The service initializer.</param>
 public AcceleratedmobilepageurlService(Google.Apis.Services.BaseClientService.Initializer initializer)
     : base(initializer)
 {
     ampUrls = new AmpUrlsResource(this);
 }
Esempio n. 20
0
 /// <summary>Constructs a new service.</summary>
 /// <param name="initializer">The service initializer.</param>
 public CloudNaturalLanguageService(Google.Apis.Services.BaseClientService.Initializer initializer)
     : base(initializer)
 {
     documents = new DocumentsResource(this);
 }
Esempio n. 21
0
 /// <summary>Constructs a new service.</summary>
 /// <param name="initializer">The service initializer.</param>
 public AppsactivityService(Google.Apis.Services.BaseClientService.Initializer initializer)
     : base(initializer)
 {
     activities = new ActivitiesResource(this);
 }
Esempio n. 22
0
 /// <summary>Constructs a new service.</summary>
 /// <param name="initializer">The service initializer.</param>
 public AndroidPublisherService(Google.Apis.Services.BaseClientService.Initializer initializer)
     : base(initializer)
 {
     purchases = new PurchasesResource(this);
 }
 /// <summary>Constructs a new service.</summary>
 /// <param name="initializer">The service initializer.</param>
 public TexttospeechService(Google.Apis.Services.BaseClientService.Initializer initializer)
     : base(initializer)
 {
     text   = new TextResource(this);
     voices = new VoicesResource(this);
 }
 /// <summary>Constructs a new service.</summary>
 /// <param name="initializer">The service initializer.</param>
 public CloudOSLoginService(Google.Apis.Services.BaseClientService.Initializer initializer)
     : base(initializer)
 {
     users = new UsersResource(this);
 }
 /// <summary>Constructs a new service.</summary>
 /// <param name="initializer">The service initializer.</param>
 public PolicyAnalyzerService(Google.Apis.Services.BaseClientService.Initializer initializer) : base(initializer)
 {
     Projects = new ProjectsResource(this);
 }
 /// <summary>Constructs a new service.</summary>
 /// <param name="initializer">The service initializer.</param>
 public AppStateService(Google.Apis.Services.BaseClientService.Initializer initializer)
     : base(initializer)
 {
     states = new StatesResource(this);
 }
Esempio n. 27
0
 /// <summary>Constructs a new service.</summary>
 /// <param name="initializer">The service initializer.</param>
 public CloudRuntimeConfigService(Google.Apis.Services.BaseClientService.Initializer initializer)
     : base(initializer)
 {
     operations = new OperationsResource(this);
 }
 /// <summary>Constructs a new service.</summary>
 /// <param name="initializer">The service initializer.</param>
 public CloudIAPService(Google.Apis.Services.BaseClientService.Initializer initializer)
     : base(initializer)
 {
     v1 = new V1Resource(this);
 }
 /// <summary>Constructs a new service.</summary>
 /// <param name="initializer">The service initializer.</param>
 public UrlshortenerService(Google.Apis.Services.BaseClientService.Initializer initializer)
     : base(initializer)
 {
     url = new UrlResource(this);
 }
 /// <summary>Constructs a new service.</summary>
 /// <param name="initializer">The service initializer.</param>
 public LicensingService(Google.Apis.Services.BaseClientService.Initializer initializer)
     : base(initializer)
 {
     licenseAssignments = new LicenseAssignmentsResource(this);
 }
Esempio n. 31
0
 /// <summary>Constructs a new service.</summary>
 /// <param name="initializer">The service initializer.</param>
 public SecurityCommandCenterService(Google.Apis.Services.BaseClientService.Initializer initializer)
     : base(initializer)
 {
     organizations = new OrganizationsResource(this);
 }
Esempio n. 32
0
        public void LoginToGoogle(string username)
        {
            Logger.Log("Connecting to Google...", EventType.Information);
            if (ContactsRequest == null && SyncContacts || DocumentsRequest == null && SyncNotes || EventRequest == null & SyncAppointments)
            {
                //OAuth2 for all services
                List<String> scopes = new List<string>();

                //Contacts-Scope
                scopes.Add("https://www.google.com/m8/feeds");
                //Notes-Scope
                scopes.Add("https://docs.google.com/feeds/");
                //scopes.Add("https://docs.googleusercontent.com/");
                //scopes.Add("https://spreadsheets.google.com/feeds/");
                //Calendar-Scope
                //scopes.Add("https://www.googleapis.com/auth/calendar");
                scopes.Add(CalendarService.Scope.Calendar);

                //take user credentials
                UserCredential credential;

                //load client secret from ressources
                byte[] jsonSecrets = Properties.Resources.client_secrets;

                //using (var stream = new FileStream(Application.StartupPath + "\\client_secrets.json", FileMode.Open, FileAccess.Read))
                using (var stream = new MemoryStream(jsonSecrets))
                {
                    FileDataStore fDS = new FileDataStore(Logger.AuthFolder, true);

                    GoogleClientSecrets clientSecrets = GoogleClientSecrets.Load(stream);

                    credential = GCSMOAuth2WebAuthorizationBroker.AuthorizeAsync(
                                    clientSecrets.Secrets,
                                    scopes.ToArray(),
                                    username,
                                    CancellationToken.None,
                                    fDS).
                                    Result;

                    var initializer = new Google.Apis.Services.BaseClientService.Initializer();
                    initializer.HttpClientInitializer = credential;

                    OAuth2Parameters parameters = new OAuth2Parameters
                    {
                        ClientId = clientSecrets.Secrets.ClientId,
                        ClientSecret = clientSecrets.Secrets.ClientSecret,

                        // Note: AccessToken is valid only for 60 minutes
                        AccessToken = credential.Token.AccessToken,
                        RefreshToken = credential.Token.RefreshToken
                    };
                    Logger.Log(Application.ProductName, EventType.Information);
                    RequestSettings settings = new RequestSettings(
                        Application.ProductName, parameters);

                    if (SyncContacts)
                    {
                        //ContactsRequest = new ContactsRequest(rs);
                        ContactsRequest = new ContactsRequest(settings);
                    }

                    if (SyncNotes)
                    {
                        //DocumentsRequest = new DocumentsRequest(rs);
                        DocumentsRequest = new DocumentsRequest(settings);

                        //Instantiate an Authenticator object according to your authentication, to use ResumableUploader
                        //GDataCredentials cred = new GDataCredentials(credential.Token.AccessToken);
                        //GOAuth2RequestFactory rf = new GOAuth2RequestFactory(null, Application.ProductName, parameters);
                        //DocumentsRequest.Service.RequestFactory = rf;

                        authenticator = new OAuth2Authenticator(Application.ProductName, parameters);
                    }
                    if (SyncAppointments)
                    {
                        //ContactsRequest = new Google.Contacts.ContactsRequest()
                        var CalendarRequest = new CalendarService(initializer);

                        //CalendarRequest.setUserCredentials(username, password);

                        calendarList = CalendarRequest.CalendarList.List().Execute().Items;

                        //Get Primary Calendar, if not set from outside
                        if (string.IsNullOrEmpty(SyncAppointmentsGoogleFolder))
                            foreach (var calendar in calendarList)
                            {
                                if (calendar.Primary != null && calendar.Primary.Value)
                                {
                                    SyncAppointmentsGoogleFolder = calendar.Id;
                                    break;
                                }
                            }

                        if (SyncAppointmentsGoogleFolder == null)
                            throw new Exception("Google Calendar not defined (primary not found)");

                        //EventQuery query = new EventQuery("https://www.google.com/calendar/feeds/default/private/full");
                        //Old v2 approach: EventQuery query = new EventQuery("https://www.googleapis.com/calendar/v3/calendars/default/events");
                        EventRequest = CalendarRequest.Events;
                    }
                }
            }

            Synchronizer.UserName = username;

            int maxUserIdLength = Synchronizer.OutlookUserPropertyMaxLength - (Synchronizer.OutlookUserPropertyTemplate.Length - 3 + 2);//-3 = to remove {0}, +2 = to add length for "id" or "up"
            string userId = username;
            if (userId.Length > maxUserIdLength)
                userId = userId.GetHashCode().ToString("X"); //if a user id would overflow UserProperty name, then use that user id hash code as id.
            //Remove characters not allowed for Outlook user property names: []_#
            userId = userId.Replace("#", "").Replace("[", "").Replace("]", "").Replace("_", "");

            OutlookPropertyPrefix = string.Format(Synchronizer.OutlookUserPropertyTemplate, userId);
        }
Esempio n. 33
0
 /// <summary>Constructs a new service.</summary>
 /// <param name="initializer">The service initializer.</param>
 public PredictionService(Google.Apis.Services.BaseClientService.Initializer initializer)
     : base(initializer)
 {
     hostedmodels  = new HostedmodelsResource(this);
     trainedmodels = new TrainedmodelsResource(this);
 }