Beispiel #1
0
    public string GetSpreadsheets(Hashtable State, RadComboBox Spreadsheets)
    {
        try
        {
            SpreadsheetsService service = new SpreadsheetsService(State["SelectedApp"].ToString());

            GOAuthRequestFactory requestFactory = new GOAuthRequestFactory("wise", "MobiFlex");
            requestFactory.ConsumerKey = ConfigurationManager.AppSettings["GoogleAppsKey"];
            requestFactory.ConsumerSecret = ConfigurationManager.AppSettings["GoogleAppsSecret"];
            service.RequestFactory = requestFactory;
            //get all spreadsheets
            Google.GData.Spreadsheets.SpreadsheetQuery query = new Google.GData.Spreadsheets.SpreadsheetQuery();
            query.OAuthRequestorId = State["CustomerEmail"].ToString();
            query.Uri = new Uri("https://spreadsheets.google.com/feeds/spreadsheets/private/full?xoauth_requestor_id=" + State["CustomerEmail"].ToString());

            SpreadsheetFeed feed = service.Query(query);

            Spreadsheets.Items.Clear();
            Spreadsheets.Items.Add(new RadComboBoxItem("Select Spreadsheet ->", "->"));
            foreach (SpreadsheetEntry entry in feed.Entries)
            {
                string spreadsheet_name = entry.Title.Text;
                Spreadsheets.Items.Add(new RadComboBoxItem(spreadsheet_name, spreadsheet_name));
            }
            return "OK";
        }
        catch (Exception ex)
        {
            Util util = new Util();
            util.LogError(State, ex);
            return ex.Message;
        }
    }
        public void AuthenticateV2()
        {
            // create an OAuth factory to use
            log.Debug("Authenticating to calendar service using 2-legged OAuth");
            GOAuthRequestFactory requestFactory = new GOAuthRequestFactory("cl", "MyApp");
            requestFactory.ConsumerKey = ConfigurationManager.AppSettings["consumerKey"];
            requestFactory.ConsumerSecret = ConfigurationManager.AppSettings["consumerSecret"];

            service = new CalendarService("MyApp");
            service.RequestFactory = requestFactory;
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            try
            {
                // create an OAuth factory to use
                GOAuthRequestFactory requestFactory = new GOAuthRequestFactory("cl", "MyApp");
                requestFactory.ConsumerKey = "CONSUMER_KEY";
                requestFactory.ConsumerSecret = "CONSUMER_SECRET";

                // example of performing a query (use OAuthUri or query.OAuthRequestorId)
                Uri calendarUri = new OAuthUri("http://www.google.com/calendar/feeds/default/owncalendars/full", "USER", "DOMAIN");
                // can use plain Uri if setting OAuthRequestorId in the query
                // Uri calendarUri = new Uri("http://www.google.com/calendar/feeds/default/owncalendars/full");

                CalendarQuery query = new CalendarQuery();
                query.Uri = calendarUri;
                query.OAuthRequestorId = "USER@DOMAIN"; // can do this instead of using OAuthUri for queries

                CalendarService service = new CalendarService("MyApp");
                service.RequestFactory = requestFactory;
                service.Query(query);
                Console.WriteLine("Query Success!");

                // example with insert (must use OAuthUri)
                Uri contactsUri = new OAuthUri("http://www.google.com/m8/feeds/contacts/default/full", "USER", "DOMAIN");

                ContactEntry entry = new ContactEntry();
                EMail primaryEmail = new EMail("*****@*****.**");
                primaryEmail.Primary = true;
                primaryEmail.Rel = ContactsRelationships.IsHome;
                entry.Emails.Add(primaryEmail);

                ContactsService contactsService = new ContactsService("MyApp");
                contactsService.RequestFactory = requestFactory;
                contactsService.Insert(contactsUri, entry); // this could throw if contact exists

                Console.WriteLine("Insert Success!");

                // to perform a batch use
                // service.Batch(batchFeed, new OAuthUri(atomFeed.Batch, userName, domain));

                Console.ReadKey();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Fail!");
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.StackTrace);
                Console.ReadKey();
            }
        }
Beispiel #4
0
            protected override void ProcessRecord()
            {
                adminUser = credentials.UserName;
                adminPassword = new Dgc.ConvertToUnsecureString(credentials.Password).PlainString;
                var _domain = dgcGoogleAppsService.GetDomain(adminUser);

                try
                {
                    //AppsService
                    service.AppsService = new AppsService(_domain, adminUser, adminPassword);

                    //CalendarService
                    var _calendarService = new CalendarService("Calendar");
                    _calendarService.setUserCredentials(adminUser, adminPassword);
                    service.CalendarService = _calendarService;

                    //OauthCalendarService
                    if (consumerKey != null)
                    {
                        if (consumerSecret == null)
                        {
                            throw new Exception("-ConsumerSecret can't be null");
                        }
                        var _oauthCalendarService = new CalendarService("Calendar");
                        var _oauth = new GDataTypes.Oauth();
                        _oauth.ConsumerKey = consumerKey;
                        _oauth.ConsumerSecret = consumerSecret;
                        service.Oauth = _oauth;
                        GOAuthRequestFactory _requestFactory = new GOAuthRequestFactory("cl", "GDataCmdLet");
                        _requestFactory.ConsumerKey = _oauth.ConsumerKey;
                        _requestFactory.ConsumerSecret = _oauth.ConsumerSecret;
                        _oauthCalendarService.RequestFactory = _requestFactory;
                        service.OauthCalendarService = _oauthCalendarService;
                    }

                    //MailSettingsService
                    var _googleMailSettingsService = new GoogleMailSettingsService(_domain, "GMailSettingsService");
                    _googleMailSettingsService.setUserCredentials(adminUser, adminPassword);
                    service.GoogleMailSettingsService = _googleMailSettingsService;

                    //ProfileService
                    var _dgcGoogleProfileService = new Dgc.GoogleProfileService();
                    service.ProfileService = _dgcGoogleProfileService.GetAuthToken(adminUser, adminPassword);

                    //ResourceService
                    var _dgcGoogleResourceService = new Dgc.GoogleResourceService();
                    service.ResourceService = _dgcGoogleResourceService.GetAuthToken(adminUser, adminPassword);

                    //ContactsService
                    var _contactService = new ContactsService("GData");
                    _contactService.setUserCredentials(adminUser, adminPassword);
                    service.ContactsService = _contactService;

                    WriteObject(service);
                }
                catch (AppsException _exception)
                {
                    WriteObject(_exception, true);
                }
            }
        public void OAuth3LeggedAuthenticationTest() {
            Tracing.TraceMsg("Entering OAuth3LeggedAuthenticationTest");

            CalendarService service = new CalendarService("OAuthTestcode");

            OAuthParameters parameters = new OAuthParameters() {
                ConsumerKey = this.oAuthConsumerKey,
                ConsumerSecret = this.oAuthConsumerSecret,
                Token = this.oAuthToken,
                TokenSecret = this.oAuthTokenSecret,
                Scope = this.oAuthScope,
                SignatureMethod = this.oAuthSignatureMethod
            };

            GOAuthRequestFactory requestFactory = new GOAuthRequestFactory("cl", "OAuthTestcode", parameters);
            service.RequestFactory = requestFactory;

            CalendarEntry calendar = new CalendarEntry();
            calendar.Title.Text = "Test OAuth";

            Uri postUri = new Uri("https://www.google.com/calendar/feeds/default/owncalendars/full");
            CalendarEntry createdCalendar = (CalendarEntry)service.Insert(postUri, calendar);

            // delete the new entry
            createdCalendar.Delete();
        }
        public void OAuth2LeggedAuthenticationTest() {
            Tracing.TraceMsg("Entering OAuth2LeggedAuthenticationTest");

            CalendarService service = new CalendarService("OAuthTestcode");

            GOAuthRequestFactory requestFactory = new GOAuthRequestFactory("cl", "OAuthTestcode");
            requestFactory.ConsumerKey = this.oAuthConsumerKey;
            requestFactory.ConsumerSecret = this.oAuthConsumerSecret;
            requestFactory.UseSSL = true;
            service.RequestFactory = requestFactory;

            CalendarEntry calendar = new CalendarEntry();
            calendar.Title.Text = "Test OAuth";

            OAuthUri postUri = new OAuthUri("https://www.google.com/calendar/feeds/default/owncalendars/full",
                this.oAuthUser,
                this.oAuthDomain);
            CalendarEntry createdCalendar = (CalendarEntry)service.Insert(postUri, calendar);
        }
Beispiel #7
0
    public string ParseGoogleDocsSpreadsheet(Hashtable State, string use_spreadsheet_name)
    {
        try
        {
            SpreadsheetsService service = new SpreadsheetsService(State["SelectedApp"].ToString());
            GOAuthRequestFactory requestFactory = new GOAuthRequestFactory("wise", "MobiFlex");
            requestFactory.ConsumerKey = ConfigurationManager.AppSettings["GoogleAppsKey"];
            requestFactory.ConsumerSecret = ConfigurationManager.AppSettings["GoogleAppsSecret"];
            service.RequestFactory = requestFactory;

            //get all spreadsheets
            Google.GData.Spreadsheets.SpreadsheetQuery query = new Google.GData.Spreadsheets.SpreadsheetQuery();
            query.OAuthRequestorId = State["CustomerEmail"].ToString();
            query.Uri = new Uri("https://spreadsheets.google.com/feeds/spreadsheets/private/full?xoauth_requestor_id=" + State["CustomerEmail"].ToString());

            SpreadsheetFeed feed = service.Query(query);

            bool found_spreadsheet = false;
            Hashtable tables = new Hashtable();
            foreach (SpreadsheetEntry entry in feed.Entries)
            {
                string spreadsheet_name = entry.Title.Text;
                if (spreadsheet_name.ToLower() == use_spreadsheet_name.ToLower())
                {
                    //Use this spreadsheet
                    found_spreadsheet = true;
                    AtomLink link = entry.Links.FindService(GDataSpreadsheetsNameTable.WorksheetRel, null);

                    //get all worksheets
                    WorksheetQuery wk_query = new WorksheetQuery(link.HRef.ToString());
                    WorksheetFeed wk_feed = service.Query(wk_query);

                    foreach (WorksheetEntry worksheet in wk_feed.Entries)
                    {
                        string table_name = worksheet.Title.Text;

                        AtomLink listFeedLink = worksheet.Links.FindService(GDataSpreadsheetsNameTable.ListRel, null);

                        ListQuery list_query = new ListQuery(listFeedLink.HRef.ToString());
                        ListFeed list_feed = service.Query(list_query);

                        //get field names
                        if (list_feed.Entries.Count == 0)
                        {
                            return "The worksheet " + table_name + " has no values.";
                        }
                        ListEntry fieldRow = (ListEntry)list_feed.Entries[0];
                        ArrayList field_list = new ArrayList();
                        foreach (ListEntry.Custom column in fieldRow.Elements)
                        {
                            Hashtable field = new Hashtable();
                            field["name"] = column.LocalName;
                            field_list.Add(field);
                        }
                        tables[table_name] = field_list;
                    }
                    break;
                }
            }
            if (!found_spreadsheet)
            {
                return use_spreadsheet_name + " could not be found";
            }

            Util util = new Util();
            string connection_string = "spreadsheet=" + use_spreadsheet_name +
                ";consumer_key=" + ConfigurationManager.AppSettings["GoogleAppsKey"] +
                ";consumer_secret=" + ConfigurationManager.AppSettings["GoogleAppsSecret"] +
                ";requestor_id=" + State["Username"].ToString();
            State["DBConnectionString"] = connection_string;
            util.SaveDatabaseSchema(State, "GoogleDocs", connection_string, tables);

            return "OK";
        }
        catch (Exception ex)
        {
            Util util = new Util();
            util.LogError(State, ex);
            if (ex.Message.Contains("Execution of request failed"))
                return "Credentials to your Google Docs Account or spreadsheet name are not valid.";
            else
                return "There was an internal error with access to your Google Docs account.";
        }
    }
 /// <summary>
 /// default constructor.
 /// </summary>
 internal GOAuthRequest(GDataRequestType type, Uri uriTarget, GOAuthRequestFactory factory) 
     : base(type, uriTarget, factory) {
     this.factory = factory;
 }
Beispiel #9
0
 /// <summary>
 /// default constructor.
 /// </summary>
 internal GOAuthRequest(GDataRequestType type, Uri uriTarget, GOAuthRequestFactory factory)
     : base(type, uriTarget, factory)
 {
     this.factory = factory;
 }
        public void OAuth3LeggedAuthenticationTest()
        {
            Tracing.TraceMsg("Entering OAuth3LeggedAuthenticationTest");

            CalendarService service = new CalendarService("OAuthTestcode");

            GOAuthRequestFactory requestFactory = new GOAuthRequestFactory("cl", "OAuthTestcode");
            requestFactory.ConsumerKey = this.oAuthConsumerKey;
            requestFactory.ConsumerSecret = this.oAuthConsumerSecret;
            requestFactory.Token = this.oAuthToken;
            requestFactory.TokenSecret = this.oAuthTokenSecret;
            service.RequestFactory = requestFactory;

            CalendarEntry calendar = new CalendarEntry();
            calendar.Title.Text = "Test OAuth";

            Uri postUri = new Uri("https://www.google.com/calendar/feeds/default/owncalendars/full");
            CalendarEntry createdCalendar = (CalendarEntry)service.Insert(postUri, calendar);

            // delete the guy again

            createdCalendar.Delete();


        }