public static void getSpreadSheet(string _spreadSheetName) { DocumentsService documentsService = getDocumentsService(); // Instantiate a DocumentsListQuery object to retrieve documents. DocumentsListQuery query = new DocumentsListQuery(); // Make a request to the API and get all documents. DocumentsFeed feed = documentsService.Query(query); DocumentEntry documentEntryDefinition = new DocumentEntry(); // Iterate through all of the documents returned foreach (DocumentEntry entry in feed.Entries) { // Print the title of this document to the screen Console.WriteLine(" ---- Found - " + entry.Title.Text + "" + entry.IsSpreadsheet); } // documentEntryDefinition.Title.Text = "MyMonitisTestSpreadsheet"; // documentEntryDefinition.Categories.Add(DocumentEntry.SPREADSHEET_CATEGORY); // documentEntryHandle = documentsService.Insert(DocumentsListQuery.documentsBaseUri, documentEntryDefinition); }
void printDocumentList(OAuth2Parameters parameters) { GOAuth2RequestFactory requestFactory = new GOAuth2RequestFactory(null, "MyDocumentsListIntegration-v1", parameters); DocumentsService service = new DocumentsService("MyDocumentsListIntegration-v1"); service.RequestFactory = requestFactory; DocumentsListQuery query = new DocumentsListQuery(); DocumentsFeed feed = service.Query(query); foreach (DocumentEntry entry in feed.Entries) { Console.WriteLine(entry.Title.Text); } Console.ReadKey(); }
////////////////////////////////////////////////////////////////////// /// <summary>runs an authentication test</summary> ////////////////////////////////////////////////////////////////////// [Test] public void GoogleAuthenticationTest() { Tracing.TraceMsg("Entering Documents List Authentication Test"); DocumentsListQuery query = new DocumentsListQuery(); DocumentsService service = new DocumentsService(this.ApplicationName); if (this.userName != null) { service.Credentials = new GDataCredentials(this.userName, this.passWord); } service.RequestFactory = this.factory; DocumentsFeed feed = service.Query(query) as DocumentsFeed; ObjectModelHelper.DumpAtomObject(feed,CreateDumpFileName("AuthenticationTest")); service.Credentials = null; }
/// <summary> /// Retrieves a list of documents from the server. /// </summary> /// <returns>The list of documents as a DocumentsFeed.</returns> public DocumentsFeed GetDocs() { DocumentsListQuery query = new DocumentsListQuery(); DocumentsFeed feed = service.Query(query); return feed; }
/// <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("DocListUploader"); ((GDataRequestFactory) service.RequestFactory).KeepAlive = false; service.setUserCredentials(username, password); //force the service to authenticate DocumentsListQuery query = new DocumentsListQuery(); query.NumberToRetrieve = 1; service.Query(query); loggedIn = true; } catch(AuthenticationException e) { loggedIn = false; service = null; throw e; } }
/// <summary> /// overloaded to create typed version of Query /// </summary> /// <param name="feedQuery"></param> /// <returns>EventFeed</returns> public DocumentsFeed Query(DocumentsListQuery feedQuery) { return base.Query(feedQuery) as DocumentsFeed; }
/// <summary> /// overloaded to create typed version of Query /// </summary> /// <param name="feedQuery"></param> /// <returns>EventFeed</returns> public DocumentsFeed Query(DocumentsListQuery feedQuery) { return(base.Query(feedQuery) as DocumentsFeed); }
public void parse() { //The date and time in this moment. DateTime timeNow = DateTime.Now; //Indicate if there are new updates in Google Docs. bool isNewUpdate = false; //The title of the most recent updated document. string latestEditedTitle = ""; //The number of documents in total. int numOfDocuments = 0; //The number of unviewed documents. int unviewedDocuments = 0; //Inform the GUI to change the progress value. UpdateProgressBar(25); try { //Download the feed from Google Docs server. DocumentsListQuery query = new DocumentsListQuery(); DocumentsFeed feed = _myService.Query(query); //Inform the GUI to change the progress value. UpdateProgressBar(50); foreach (DocumentEntry entry in feed.Entries) { DateTime lastEditedTime = new DateTime(); //No use for now. DateTime lastViewedTime = timeNow; //Note: There are some Google Docs type has no lastViewed tag. // Hence, it is better to set the default value of the // lastViewedTime to be the current date and time. //Retrieve lastEditedTime and lastViewedTime from //the Extension Elements of the feeds. HandleExtensionElements(entry, ref lastEditedTime, ref lastViewedTime); //If the document is newly created document or unread updated document... if (VerifyNewDocuments(entry) || VerifyUnviewedUpdatedDocuments(entry, lastViewedTime)) { HandleNewOrUnreadUpdatedDocuments( entry, ref isNewUpdate, ref latestEditedTime, ref latestEditedTitle, ref unviewedDocuments); } //Inform the GUI to change the progress value. UpdateProgressBar(((int)(((double)numOfDocuments++ / feed.Entries.Count()) * 50)) + 50); } //Inform the GUI to change the status message. UpdateStatusMessage(unviewedDocuments.ToString() + " documents listed above."); //Inform the GUI to update and show the balloon tooltip. updateNotifyIcon( "Your Google Docs is updated", "Latest edited document: " + latestEditedTitle, unviewedDocuments, isNewUpdate); } catch (Google.GData.Client.InvalidCredentialsException) { throw; } catch (Google.GData.Client.CaptchaRequiredException) { throw; } catch (Google.GData.Client.AuthenticationException) { throw; } catch (Exception) { //Inform the GUI to change the status message. UpdateStatusMessage("Unable to connect to Google Docs server."); //Inform the GUI to UPDATE ONLY the balloon tooltip icon //and say there is no new update found. updateNotifyIcon( "", "", 0, false); } }
public static void UpdateDocs() { lock (docs_lock) { DocumentsFeed docsFeed; DocumentsListQuery query = new DocumentsListQuery (); query.Uri = new Uri (FeedUri); try { docsFeed = service.Query (query); } catch (Exception e) { docsFeed = null; Log<GDocs>.Error (e.Message); return; } docs.Clear (); foreach (DocumentEntry doc in docsFeed.Entries) { GDocsAbstractItem item = MaybeItemFromEntry (doc); if (item != null) docs.Add (item); } } }
public static void TrashDocument(GDocsAbstractItem item) { // Search for document(s) having exactly the title, // Delete the one with matching AlternateUri DocumentsListQuery query = new DocumentsListQuery (); query.Title = item.Name; query.TitleExact = true; DocumentsFeed docFeed = service.Query (query); DocumentEntry document = docFeed.Entries.FirstOrDefault (e => e.AlternateUri == item.URL) as DocumentEntry; if (document == null) return; try { document.Delete (); } catch (Exception e) { Log.Error (e.Message); Services.Notifications.Notify (GetDeleteDocumentFailedNotification ()); return; } Services.Notifications.Notify (GetDocumentDeletedNotification (item.Name)); }
static void Main(string[] args) { var localHtmlDocname = "docContents.htm"; //Get credentials Console.Write("Enter your username:"******"Enter your password:"******"my-service"); service.setUserCredentials(user, password); DocumentsFeed listFeed = null; AtomFeed feed = null; DocumentsListQuery query = null; IProgress<string> p = new Progress<string>(Console.WriteLine); //Get list of documents var getList = Task.Run(() => { p.Report("Reading list of documents"); query = new DocumentsListQuery(); feed = service.Query(query); }); getList.Wait(); foreach (DocumentEntry entry in feed.Entries.OrderBy(x => x.Title.Text)) { if (entry.IsDocument) Console.WriteLine(entry.Title.Text); } Console.WriteLine("Type the name of the document you would like to open:"); var openDocTitle = Console.ReadLine(); string contents = string.Empty; //Get list of documents var openDoc = Task.Run(() => { p.Report("Reading document contents"); query.Title = openDocTitle; feed = service.Query(query); var openMe = feed.Entries[0] as DocumentEntry; var stream = service.Query(new Uri(openMe.Content.Src.ToString())); var reader = new StreamReader(stream); contents = reader.ReadToEnd(); using (var fs = File.Create(localHtmlDocname)) { using (var writer = new StreamWriter(fs)) { contents += Environment.UserName + " was here - " + DateTime.Now.ToString() + "<br/>"; writer.Write(contents); writer.Flush(); writer.Close(); } fs.Close(); } //OPTIONAL: Uncomment to save changes BACK to the google doc /* openMe.MediaSource = new MediaFileSource(localHtmlDocname, "text/html"); var uploader = new ResumableUploader(); //Get an authenticator var authenticator = new ClientLoginAuthenticator("document-access-test", ServiceNames.Documents, service.Credentials); //Perform the upload... Console.WriteLine("Saving to Google Drive..."); uploader.Update(authenticator, openMe); */ }); openDoc.Wait(); Console.WriteLine("Opening contents of Google doc file..."); System.Diagnostics.Process.Start(localHtmlDocname); }
public string getSpreadsheetURL(string sheetName) { DocumentsService docService = new DocumentsService(this.googleAppName); docService.RequestFactory = GoogleOauthAccess.getRequestFactory(this.googleAppName, this.parameters); Google.GData.Spreadsheets.SpreadsheetQuery query = new Google.GData.Spreadsheets.SpreadsheetQuery(); DocumentsListQuery docQuery = new DocumentsListQuery(); docQuery.Title = sheetName; DocumentsFeed feed = docService.Query(docQuery); DocumentEntry entry = (DocumentEntry)feed.Entries[0]; return "https://docs.google.com/spreadsheet/ccc?key=" + entry.ResourceId.Replace("spreadsheet:", ""); }