public void RequestFactoryTest() { Service target = new Service(); // TODO: Initialize to an appropriate value IGDataRequestFactory expected = new GDataGAuthRequestFactory("cl", "test"); IGDataRequestFactory actual; target.RequestFactory = expected; actual = target.RequestFactory; Assert.AreEqual(expected, actual); }
////////////////////////////////////////////////////////////////////// /// <summary>the setup method</summary> ////////////////////////////////////////////////////////////////////// [SetUp] public override void InitTest() { base.InitTest(); GDataGAuthRequestFactory authFactory = this.factory as GDataGAuthRequestFactory; if (authFactory != null) { authFactory.Handler = this.strAuthHandler; } }
public List <PicasaWebAlbum> QueryAlbums(BackgroundWorker worker, int overallJobPercent) { // Create an authentication factory to deal with logging in. GDataGAuthRequestFactory authFactory = new GDataGAuthRequestFactory("lh2", this.m_serviceName); authFactory.AccountType = "GOOGLE_OR_HOSTED"; this.m_albumQuery = new AlbumQuery(PicasaQuery.CreatePicasaUri("default")); this.m_albumQuery.Access = PicasaQuery.AccessLevel.AccessAll; this.m_albumService = new PicasaService(authFactory.ApplicationName); this.m_albumService.RequestFactory = authFactory; // this.m_albumService.setUserCredentials(this.m_userName, this.m_password); //string token = this.m_albumService.QueryAuthenticationToken(); this.m_albumService.SetAuthenticationToken(this.mUserToken); List <PicasaWebAlbum> retval = new List <PicasaWebAlbum>(); decimal count = ((decimal)overallJobPercent / 100) * 10; int smallCount = (int)count; try { worker.ReportProgress(0, (object)"Creating proxy"); CreateAlbumProxy(); worker.ReportProgress(smallCount, (object)"Proxy created"); worker.ReportProgress(0, (object)"Querying google"); this.m_albumFeed = this.m_albumService.Query(this.m_albumQuery); worker.ReportProgress(smallCount, (object)"Done"); } catch (Exception e) { this.m_albumQuery = null; this.m_albumService.RequestFactory = null; this.m_albumService = null; this.m_albumFeed = null; retval = null; throw new Exception("PicasaReader failed when downloading album feed for " + this.m_userName, e); } if (this.m_albumFeed.Entries.Count > 0) { int percent = (int)Math.Round((decimal)((overallJobPercent - (smallCount * 2)) / this.m_albumFeed.Entries.Count), 0); worker.ReportProgress(0, (object)"Processing album data"); foreach (PicasaEntry entry in this.m_albumFeed.Entries) { AlbumAccessor ac = new AlbumAccessor(entry); retval.Add(new PicasaWebAlbum(entry.Title.Text, entry.Updated, ac.NumPhotos, Convert.ToUInt64(ac.Id))); worker.ReportProgress(percent, null); } } this.m_albumQuery = null; this.m_albumService.RequestFactory = null; this.m_albumService = null; this.m_albumFeed = null; return(retval); }
////////////////////////////////////////////////////////////////////// /// <summary>the setup method</summary> ////////////////////////////////////////////////////////////////////// [SetUp] public override void InitTest() { base.InitTest(); GDataGAuthRequestFactory authFactory = this.factory as GDataGAuthRequestFactory; if (authFactory != null) { authFactory.Handler = this.strAuthHandler; } FeedCleanup(this.bloggerURI, this.userName, this.passWord, VersionDefaults.Major); }
public void StrictRedirectTest() { string service = "TestValue"; // TODO: Initialize to an appropriate value string applicationName = "TestValue"; // TODO: Initialize to an appropriate value GDataGAuthRequestFactory target = new GDataGAuthRequestFactory(service, applicationName); // TODO: Initialize to an appropriate value bool expected = true; // TODO: Initialize to an appropriate value bool actual; target.StrictRedirect = expected; actual = target.StrictRedirect; Assert.AreEqual(expected, actual); }
/// <summary> /// notifier if someone changes the requestfactory of the service /// </summary> public override void OnRequestFactoryChanged() { base.OnRequestFactoryChanged(); GDataGAuthRequestFactory factory = this.RequestFactory as GDataGAuthRequestFactory; if (factory != null && this.developerID != null) { RemoveOldKeys(factory.CustomHeaders); factory.CustomHeaders.Add(GoogleAuthentication.YouTubeDevKey + this.developerID); factory.Handler = YouTubeService.AuthenticationHandler; } }
public void NumberOfRetriesTest() { string service = "TestValue"; // TODO: Initialize to an appropriate value string applicationName = "TestValue"; // TODO: Initialize to an appropriate value GDataGAuthRequestFactory target = new GDataGAuthRequestFactory(service, applicationName); // TODO: Initialize to an appropriate value int expected = 2; // TODO: Initialize to an appropriate value int actual; target.NumberOfRetries = expected; actual = target.NumberOfRetries; Assert.AreEqual(expected, actual); }
public void UserAgentTest() { string service = "TestValue"; // TODO: Initialize to an appropriate value string applicationName = "TestValue"; // TODO: Initialize to an appropriate value GDataGAuthRequestFactory target = new GDataGAuthRequestFactory(service, applicationName); // TODO: Initialize to an appropriate value string expected = "TestValue"; string actual; target.UserAgent = expected; actual = target.UserAgent; Assert.AreEqual(expected, actual); }
//static string user1name = ConfigurationManager.AppSettings["CalendarUser1"].ToString(); //static string user1pwd = ConfigurationManager.AppSettings["Calendarpass1"].ToString(); public static void AddEvent1(CalendarService service, string id, string title, string contents, string location, DateTime startTime, DateTime endTime, string calendarName, string emailId) { try { Google.GData.Calendar.EventEntry entry = new Google.GData.Calendar.EventEntry(); // Set the title and content of the entry. entry.Title.Text = id + "-" + title; entry.Content.Content = contents; // Set a location for the event. Where eventLocation = new Where(); eventLocation.ValueString = location; entry.Locations.Add(eventLocation); When eventTime = new When(startTime, endTime); entry.Times.Add(eventTime); GoogleCalendar ggadmin = new GoogleCalendar(calendarName, AdminuserName, AdminuserPwd); // string CalendarId = ggadmin.GetCalendarId(); //CalendarService Calservice = new CalendarService("CalendarSampleApp"); AclEntry aclEntry = new AclEntry(); aclEntry.Scope = new AclScope(); aclEntry.Scope.Type = AclScope.SCOPE_USER; aclEntry.Scope.Value = emailId; aclEntry.Role = AclRole.ACL_CALENDAR_READ; // Uri postUri = new Uri("https://www.google.com/calendar/feeds/" + CalendarId + "/private/full"); Uri aclUri = new Uri(string.Format("https://www.google.com/calendar/feeds/{0}/acl/full", service.Credentials.Username.ToString())); GDataGAuthRequestFactory requestFactory = (GDataGAuthRequestFactory)service.RequestFactory; IWebProxy iProxy = WebRequest.GetSystemWebProxy(); WebProxy myProxy = new WebProxy(); // potentially, setup credentials on the proxy here myProxy.Credentials = CredentialCache.DefaultCredentials; myProxy.UseDefaultCredentials = false; // requestFactory.CreateRequest(GDataRequestType.Insert, postUri);// = myProxy; // Send the request and receive the response: //AtomEntry insertEntry = service.Insert(postUri, entry); AclEntry insertedEntry = service.Insert(aclUri, aclEntry) as AclEntry; } catch (Exception ex) { //LogManager.Instance.WriteToFlatFile(ex.Message); } }
/// <summary> /// notifier if someone changes the requestfactory of the service /// </summary> public override void OnRequestFactoryChanged() { base.OnRequestFactoryChanged(); GDataGAuthRequestFactory factory = this.RequestFactory as GDataGAuthRequestFactory; if (factory != null && this.devKey != null) { RemoveWebKey(factory.CustomHeaders); factory.CustomHeaders.Add(GoogleAuthentication.WebKey + this.devKey); if (this.authHandlerSet == true) { factory.Handler = this.authHandler == null ? null : this.authHandler.ToString(); } } }
public AnalyticsProxy(GDataGAuthRequestFactory request) { this.ProxyAddress = Settings.Default.ProxyUrl; if (ProxyAddress.Length == 0) { request.Proxy = MyProxy; } else { this.UserName = Settings.Default.AnalyticsProxyUsername; this.Password = Settings.Default.AnalyticsProxyPassword; this.NewUri = new Uri(ProxyAddress); MyProxy = new WebProxy(); MyProxy.GetProxy(NewUri); MyProxy.Credentials = new NetworkCredential(UserName, Password); request.Proxy = MyProxy; } }
public List <String> getProfileIdList() { try { List <String> profilesIdList = new List <String>(); GDataGAuthRequestFactory requestFactory = new GDataGAuthRequestFactory("analytics", "GTGATracker"); requestFactory.AccountType = "GOOGLE"; AnalyticsProxy = new AnalyticsProxy(requestFactory); this.RequestFactory = requestFactory; this.setUserCredentials(GetEmail(), GetPassword()); string queri = ConfigurationManager.AppSettings["FeedAccountsUri"] + ConfigurationManager.AppSettings["API_Key"]; string webProfileId = ""; string webPropertie = ""; string profileIdUrl = ""; List <String> webProfilesList = new List <String>(); List <String> idList = new List <String>(); DataQuery query = new DataQuery(queri); DataFeed feedWebProperty = this.Query(query); foreach (AtomEntry entry in feedWebProperty.Entries) { webProfileId = entry.Links[1].HRef.Content; DataQuery propertyQuery = new DataQuery(webProfileId); DataFeed feedProfile = this.Query(propertyQuery); foreach (DataEntry entri in feedProfile.Entries) { webPropertie = entri.Links[2].HRef.Content; DataQuery profileIdQuery = new DataQuery(webPropertie); DataFeed feedProfileId = this.Query(profileIdQuery); foreach (DataEntry entrie in feedProfileId.Entries) { idList.Add(entrie.Links[0].HRef.Content); profileIdUrl = entrie.Links[0].HRef.Content; } } } return(idList); } catch (GDataRequestException e) { throw e; } }
/* public string LoginToGoogle(out string token) * { * GDataGAuthRequestFactory authFactory = new GDataGAuthRequestFactory("lh2", this.m_serviceName); * authFactory.AccountType = "GOOGLE_OR_HOSTED"; * * this.m_albumService = new PicasaService(authFactory.ApplicationName); * try * { * this.m_albumService.setUserCredentials(this.m_userName, this.m_password); * this.m_albumService.QueryAuthenticationToken(); // Authenticate the user immediately * } * catch (CaptchaRequiredException e) * { * token = e.Token; * return e.Url; * } * } * * public string LoginToGoogle(out string token, string CAPTCHAAnswer, string CAPTCHAToken) * { * GDataGAuthRequestFactory authFactory = new GDataGAuthRequestFactory("lh2", this.m_serviceName); * authFactory.AccountType = "GOOGLE_OR_HOSTED"; * string token = string.Empty; * this.m_albumService = new PicasaService(authFactory.ApplicationName); * authFactory.CaptchaAnswer = CAPTCHAAnswer; * authFactory.CaptchaToken = CAPTCHAToken; * this.m_albumService.setUserCredentials(this.m_userName, this.m_password); * * token = this.m_albumService.QueryAuthenticationToken(); // Authenticate the user immediately * return token; * * * } */ public List <PicasaWebAlbum> QueryAlbums() { // Create an authentication factory to deal with logging in. GDataGAuthRequestFactory authFactory = new GDataGAuthRequestFactory("lh2", this.m_serviceName); authFactory.AccountType = "GOOGLE_OR_HOSTED"; this.m_albumService = new PicasaService(authFactory.ApplicationName); this.m_albumService.RequestFactory = authFactory; this.m_albumService.SetAuthenticationToken(this.mUserToken); this.m_albumQuery = new AlbumQuery(PicasaQuery.CreatePicasaUri("default")); this.m_albumQuery.Access = PicasaQuery.AccessLevel.AccessAll; List <PicasaWebAlbum> retval = new List <PicasaWebAlbum>(); try { CreateAlbumProxy(); this.m_albumFeed = this.m_albumService.Query(this.m_albumQuery); } catch (Exception e) { this.m_albumQuery = null; this.m_albumService.RequestFactory = null; this.m_albumService = null; this.m_albumFeed = null; retval = null; throw new Exception("PicasaReader failed when downloading album feed for " + this.m_userName, e); } foreach (PicasaEntry entry in this.m_albumFeed.Entries) { AlbumAccessor ac = new AlbumAccessor(entry); retval.Add(new PicasaWebAlbum(entry.Title.Text, entry.Updated, ac.NumPhotos, Convert.ToUInt64(ac.Id))); } this.m_albumQuery = null; this.m_albumService.RequestFactory = null; this.m_albumService = null; this.m_albumFeed = null; return(retval); }
private void button1_Click(object sender, EventArgs e) { string CLIENT_ID = "978724980491-bvs462ns4r1p81g5vjcji6ue1cg5e5nd.apps.googleusercontent.com"; string CLIENT_SECRET = "Zf-TZntewp7gF23Rg3xzV8Jl"; //string SCOPE = "https://spreadsheets.google.com/feeds https://docs.google.com/feeds"; string REDIRECT_URI = "urn:ietf:wg:oauth:2.0:oob"; var parameters = new OAuth2Parameters() { //Client ClientId = CLIENT_ID, ClientSecret = CLIENT_SECRET, RedirectUri = REDIRECT_URI, Scope = "https://www.google.com/m8/feeds", ResponseType = "code" }; //User clicks this auth url and will then be sent to your redirect url with a code parameter var authorizationUrl = OAuthUtil.CreateOAuth2AuthorizationUrl(parameters); Service service = new Service("blogger", ""); service.Credentials = new GDataCredentials("*****@*****.**", "1q2w3e4r!@#"); GDataGAuthRequestFactory factory = (GDataGAuthRequestFactory)service.RequestFactory; factory.AccountType = "GOOGLE"; AtomEntry newPost = new AtomEntry(); newPost.Title.Text = "Test"; newPost.Content = new AtomContent(); newPost.Content.Content = "Testpostssssssssssssssssssssss"; newPost.Content.Type = "xhtml"; // newPost.IsDraft = true; string blogID = "6927940079287773210"; Uri blogFeedUri = new Uri("http://www.blogger.com/feeds/" + blogID + "/posts/default"); AtomEntry createdEntry = service.Insert(blogFeedUri, newPost); }
public List <PicasaWebPhoto> QueryPhoto(string tags) { List <PicasaWebPhoto> retval = new List <PicasaWebPhoto>(); GDataGAuthRequestFactory authFactory = new GDataGAuthRequestFactory("lh2", this.m_serviceName); authFactory.AccountType = "GOOGLE_OR_HOSTED"; this.m_photoQuery = new PhotoQuery(PicasaQuery.CreatePicasaUri(this.m_userName, this.m_albumName)); this.m_photoQuery.Tags = tags; this.m_photoService = new PicasaService(authFactory.ApplicationName); this.m_photoService.RequestFactory = authFactory; //this.m_photoService.setUserCredentials(this.m_userName, this.m_password); this.m_photoService.SetAuthenticationToken(this.mUserToken); CreatePhotoProxy(); try { this.m_photoFeed = this.m_photoService.Query(this.m_photoQuery); foreach (PicasaEntry photo in this.m_photoFeed.Entries) { retval.Add(new PicasaWebPhoto(photo, this.m_albumName)); } } catch (Exception e) { throw new Exception("Query Photo Exception", e); } finally { this.m_photoQuery = null; this.m_photoService.RequestFactory = null; this.m_photoService = null; this.m_photoFeed = null; } return(retval); }
// Validates a username/pass by attempting to login to calendar public static bool checkPw(string username, string password) { GDataGAuthRequestFactory authFactory = new GDataGAuthRequestFactory("cl", "Seadragon"); authFactory.AccountType = "HOSTED"; CalendarService client = new CalendarService(authFactory.ApplicationName); client.RequestFactory = authFactory; client.setUserCredentials(username + "@" + DOMAIN, password); try { client.QueryClientLoginToken(); // Authenticate the user immediately } catch (WebException) // Invalid login { return(false); } return(true); }
public static void AddEvent(CalendarService service, string id, string title, string contents, string location, DateTime startTime, DateTime endTime, string calendarName) { try { Google.GData.Calendar.EventEntry entry = new Google.GData.Calendar.EventEntry(); // Set the title and content of the entry. entry.Title.Text = id + "-" + title; entry.Content.Content = contents; // Set a location for the event. Where eventLocation = new Where(); eventLocation.ValueString = location; entry.Locations.Add(eventLocation); When eventTime = new When(startTime, endTime); entry.Times.Add(eventTime); GoogleCalendar ggadmin = new GoogleCalendar(calendarName, AdminuserName, AdminuserPwd); string CalendarId = ggadmin.GetCalendarId(); Uri postUri = new Uri("https://www.google.com/calendar/feeds/" + CalendarId + "/private/full"); GDataGAuthRequestFactory requestFactory = (GDataGAuthRequestFactory)service.RequestFactory; IWebProxy iProxy = WebRequest.GetSystemWebProxy(); WebProxy myProxy = new WebProxy(); // potentially, setup credentials on the proxy here myProxy.Credentials = CredentialCache.DefaultCredentials; myProxy.UseDefaultCredentials = false; requestFactory.CreateRequest(GDataRequestType.Insert, postUri);// = myProxy; // Send the request and receive the response: AtomEntry insertedEntry = service.Insert(postUri, entry); } catch (Exception ex) { //LogManager.Instance.WriteToFlatFile(ex.Message); } }
/// <summary> /// Authenticates to Google servers /// </summary> /// <param name="username">The user's username (e-mail)</param> /// <param name="password">The user's password</param> /// <exception cref="AuthenticationException">Thrown on invalid credentials.</exception> public void Login(string username, string password) { if (loggedIn) { throw new ApplicationException("Already logged in."); } try { service = new DocumentsService(APP_NAME); GDataGAuthRequestFactory reqFactory = (GDataGAuthRequestFactory)service.RequestFactory; reqFactory.KeepAlive = false; reqFactory.ProtocolMajor = 3; service.setUserCredentials(username, password); loggedIn = true; } catch (AuthenticationException e) { loggedIn = false; service = null; throw e; } }
public List <String> getWebPropertiesList() { List <String> webPropertieList = new List <String>(); GDataGAuthRequestFactory requestFactory = new GDataGAuthRequestFactory("analytics", "GTGATracker"); requestFactory.AccountType = "GOOGLE"; IWebProxy myProxy = new WebProxy(ConfigurationManager.AppSettings["ProxyUrl"]); NetworkCredential credentials = new NetworkCredential(ConfigurationManager.AppSettings["AnalyticsProxyUsername"], ConfigurationManager.AppSettings["AnalyticsProxyPassword"]); myProxy.Credentials = credentials; requestFactory.Proxy = myProxy; this.setUserCredentials(GetEmail(), GetPassword()); String queri = ConfigurationManager.AppSettings["FeedAccountsUri"] + ConfigurationManager.AppSettings["API_Key"]; DataQuery query = new DataQuery(queri); DataFeed feedWebProperty = this.Query(query); foreach (AtomEntry entry in feedWebProperty.Entries) { webPropertieList.Add(entry.Links[1].HRef.Content); } return(webPropertieList); }
public IList <Feed> FeedsList(int?quantity) { // Try to retrieve from cache string cacheKey = CacheFeedList + quantity; ICache cache = ServiceLocator.Current.GetInstance <ICache>(); IList <Feed> lst = cache.Get <IList <Feed> >(cacheKey); if (lst != null) { return(lst); } // TODO: Move hardcoded data to config file Service service = new Service("blogger", "ocaecommerce"); service.Credentials = new GDataCredentials(Config.GoogleUser, Config.GooglePass); GDataGAuthRequestFactory factory = (GDataGAuthRequestFactory)service.RequestFactory; factory.AccountType = "GOOGLE"; // Otherwise go get it lst = new List <Feed>(); FeedQuery query = new FeedQuery(); query.Uri = new Uri("http://www.blogger.com/feeds/default/blogs"); AtomFeed feed = service.Query(query); foreach (AtomEntry entry in feed.Entries) { FeedQuery feedQuery = new FeedQuery(); feedQuery.Uri = new Uri(entry.FeedUri); AtomFeed innerfeed = null; innerfeed = service.Query(feedQuery); foreach (AtomEntry innerentry in innerfeed.Entries) { Feed f = new Feed(); int feedStartIndex = innerentry.Id.AbsoluteUri.IndexOf("post-") + 5; f.Id = innerentry.Id.AbsoluteUri.Substring(feedStartIndex); f.Title = innerentry.Title.Text; f.FeedData = innerentry.Content.Content; f.FeedUrl = innerentry.AlternateUri.Content; f.DatePublished = innerentry.Published; if (quantity != null) { if (quantity.Value == 0) { break; } quantity--; } lst.Add(f); } } cache.Set(cacheKey, lst, new TimeSpan(0, 20, 0)); return(lst); }
public int sendPostToBlogspot(string blogId, string username, string password, string title, string postBody, string tags) { //CheckForIllegalCrossThreadCalls = false; int q = 0; Service service = new Service("blogger", "googleAPIshittyName"); service.Credentials = new GDataCredentials(username, password); GDataGAuthRequestFactory factory = (GDataGAuthRequestFactory)service.RequestFactory; factory.AccountType = "GOOGLE"; ///////////////////////////////////////////////////////////// if (postBody.Contains("[IMGLINK]")) { postBody = postBody.Replace("[IMGLINK]", uploadImageToGoogle("image.png", username, password, blogId)); } postBody = BaseView.RemoveHtmlTagsUsingCharArray(postBody); ///////post//////////////////////////////// AtomEntry post = new AtomEntry(); post.Title.Text = title; post.Content = new AtomContent(); post.Content.Content = postBody; post.Content.Type = "xhtml"; int length = 0; //make sure that tags are not too long string[] tagsS = tags.Split(','); foreach (string label in tagsS) { length = length + label.Count(); if (length > 198) { string label2 = label.Substring(0, 199); AtomCategory cat = new AtomCategory(); cat.Scheme = new Uri("http://www.blogger.com/atom/ns#"); cat.Term = label2; post.Categories.Add(cat); //this.txtTag.Text = this.txtTag.Text + label2 + ","; break; } else { AtomCategory cat = new AtomCategory(); cat.Scheme = new Uri("http://www.blogger.com/atom/ns#"); cat.Term = label; post.Categories.Add(cat); } } post.IsDraft = false; ///////////////publishing post/_/_/_/_/_/_\_|_/_)_(_--> () - {} - [] 0_o Uri blogFeedUri = new Uri("http://www.blogger.com/feeds/" + blogId + "/posts/default"); AtomEntry createdEntry = null; try { createdEntry = service.Insert(blogFeedUri, post); //MessageBox.Show("Done!"); Label1.Text += "Thành Công!!! <br/>"; q = 1; } catch (GDataRequestException exception) { if (exception.ResponseString == "Blog has exceeded rate limit or otherwise requires word verification for new posts") { // MessageBox.Show("Blog has exceeded rate limit or otherwise requires word verification for new posts"); Label1.Text += "Blog has exceeded rate limit or otherwise requires word verification for new posts <br/>"; q = 0; } } if (createdEntry == null) { //MessageBox.Show("Something went wrong, atricle was not published...\nCheck all html tags..."); Label1.Text += "Something went wrong, atricle was not published...\nCheck all html tags...<br/>"; q = 0; } return(q); }