/// <summary> /// Evernoteのノートブック情報を取得する /// </summary> /// <param name="EvernoteToken">Evernoteトークン</param> /// <returns>ノートブック名とノートブックGuidのDictionary</returns> static public Dictionary <string, string> GetEvetnoteNotebook(string EvernoteToken) { string authToken = EvernoteToken; Uri userStoreUrl = new Uri("https://" + evernoteHost + "/edam/user"); TTransport userStoreTransport = new THttpClient(userStoreUrl); TProtocol userStoreProtocol = new TBinaryProtocol(userStoreTransport); UserStore.Client userStore = new UserStore.Client(userStoreProtocol); String noteStoreUrl = userStore.getNoteStoreUrl(authToken); TTransport noteStoreTransport = new THttpClient(new Uri(noteStoreUrl)); TProtocol noteStoreProtocol = new TBinaryProtocol(noteStoreTransport); NoteStore.Client noteStore = new NoteStore.Client(noteStoreProtocol); List <Notebook> notebooks = noteStore.listNotebooks(authToken); Dictionary <string, string> notebookNames = new Dictionary <string, string>(); foreach (var note in notebooks) { notebookNames.Add(note.Name, note.Guid); } return(notebookNames); }
internal List <Entity.Notebook> ReadEvernoteNotebooks(String edamBaseUrl, AuthenticationResult authResult) { string authToken = authResult.AuthenticationToken; NoteStore.Client noteStore = EvernoteHelper.GetNoteStoreClient(edamBaseUrl, authResult.User); List <Notebook> notebooks = noteStore.listNotebooks(authToken); UpdateProgress("Retrieving Notebook List"); foreach (Notebook notebook in notebooks) { Entity.Notebook enNotebook = new Entity.Notebook(); enNotebook.Name = (notebook.Stack + " " + notebook.Name).Trim(); enNotebook.Guid = notebook.Guid; int intProgress = Helper.GetNotebookProgress(enNotebooks.Count, notebooks.Count, 1, 20); UpdateProgress(intProgress); NoteFilter nf = new NoteFilter(); nf.NotebookGuid = enNotebook.Guid; NoteList nl = noteStore.findNotes(authToken, nf, 0, 1); if (nl.Notes.Count > 0) { enNotebooks.Add(enNotebook); } } enNotebooks.Sort(delegate(Entity.Notebook p1, Entity.Notebook p2) { return(p1.Name.CompareTo(p2.Name)); }); return(enNotebooks); }
internal List <Entity.Notebook> ReadEvernoteNotes(String edamBaseUrl, AuthenticationResult authResult) { string authToken = authResult.AuthenticationToken; NoteStore.Client noteStore = EvernoteHelper.GetNoteStoreClient(edamBaseUrl, authResult.User); List <Notebook> notebooks = noteStore.listNotebooks(authToken); int nbCount = 1; foreach (Entity.Notebook enNotebook in enNotebooks) { int intProgress = Helper.GetNotebookProgress(nbCount++, enNotebooks.Count, 20, 60); UpdateProgress(intProgress); NoteFilter nf = new NoteFilter(); nf.NotebookGuid = enNotebook.Guid; NoteList nl = noteStore.findNotes(authToken, nf, 0, 500);//500 notes limit per notebook foreach (Note note in nl.Notes) { UpdateProgress(intProgress, "Retrieving " + enNotebook.Name + ", " + note.Title); Entity.Note enNote = new Entity.Note(); enNote.Title = note.Title; enNote.ShortDateString = note.Updated.ToString(); string enmlContent = noteStore.getNoteContent(authToken, note.Guid); enNote.LoadXml(enmlContent); if (enNotebook.Notes == null) { enNotebook.Notes = new List <Entity.Note>(); } enNotebook.Notes.Add(enNote); } } enNotebooks.Sort(delegate(Entity.Notebook p1, Entity.Notebook p2) { return(p1.Name.CompareTo(p2.Name)); }); return(enNotebooks); }
/// <summary> /// This will return a list of notebooks given a user token. /// </summary> /// <param name="authToken"></param> /// <returns></returns> public List <Notebook> GetNotebooks() { // List all of the notebooks in the user's account return(_Instance.listNotebooks(_authToken)); }
public bool BeginSyncTransaction() { Logger.Debug("[Evernote] Begining Sync..."); if (ConsumerKey.Equals("your_key_here")) { throw new Exception("You need to Update the Evernote ConsumerKey!! Open up the EvernoteSyncServer.cs file and look at it!"); } ServicePointManager.CertificatePolicy = new CertificateManager(); //ServicePointManager.ServerCertificateValidationCallback += ValidateServerCertificate; bool versionOK = _userStore.checkVersion("Tomboy.EvernoteSyncAddin", Evernote.EDAM.UserStore.Constants.EDAM_VERSION_MAJOR, Evernote.EDAM.UserStore.Constants.EDAM_VERSION_MINOR); if (!versionOK) { Logger.Error("[Evernote] EDAM protocol version not up to date: " + Evernote.EDAM.UserStore.Constants.EDAM_VERSION_MAJOR + "." + Evernote.EDAM.UserStore.Constants.EDAM_VERSION_MINOR); return(false); } string username; string password; if (!EvernoteSyncServiceAddin.GetConfigSettings(out username, out password)) { return(false); } AuthenticationResult authResult = _userStore.authenticate(username, password, ConsumerKey, ConsumerSecret); User user = authResult.User; _authToken = authResult.AuthenticationToken; Logger.Debug("[Evernote] Authentication successful for: " + user.Username); Logger.Debug("[Evernote] Authentication token = " + _authToken); String noteStoreUrl = EdamBaseUrl + "/edam/note/" + user.ShardId; TTransport noteStoreTransport = new THttpClient(noteStoreUrl); TProtocol noteStoreProtocol = new TBinaryProtocol(noteStoreTransport); _noteStore = new NoteStore.Client(noteStoreProtocol); //TODO - check if the user has a 'Tomboy' Notebook. If not, add one bool foundTomboyNotebook = false; List <Notebook> notebooks = _noteStore.listNotebooks(_authToken); foreach (Notebook notebook in notebooks) { if (notebook.Name.ToLowerInvariant().Trim().Equals("tomboy")) { foundTomboyNotebook = true; _tomboyNotebook = notebook; } } if (!foundTomboyNotebook) { // no tomboy notebook found, so try to add one _tomboyNotebook = new Notebook(); _tomboyNotebook.Name = "Tomboy"; _tomboyNotebook.DefaultNotebook = false; _tomboyNotebook.Guid = new Guid().ToString(); _tomboyNotebook = _noteStore.createNotebook(_authToken, _tomboyNotebook); if (_tomboyNotebook == null) { Logger.Error("[Evernote] Could not create 'Tomboy' notebook in evernote"); return(false); } Console.WriteLine("[Evernote] New Tomboy notebook with guid : " + _tomboyNotebook.Guid); } return(true); }
public static void RunImpl(DependencyObject dispatcherOwner, ViewModel viewModel) { if (authToken == "your developer token") { ShowMessage(dispatcherOwner, "Please fill in your devleoper token in Sample.cs"); return; } // Instantiate the libraries to connect the service TTransport userStoreTransport = new THttpClient(new Uri(UserStoreUrl)); TProtocol userStoreProtocol = new TBinaryProtocol(userStoreTransport); UserStore.Client userStore = new UserStore.Client(userStoreProtocol); // Check that the version is correct bool versionOK = userStore.checkVersion("Evernote EDAMTest (WP7)", Evernote.EDAM.UserStore.Constants.EDAM_VERSION_MAJOR, Evernote.EDAM.UserStore.Constants.EDAM_VERSION_MINOR); InvokeOnUIThread(dispatcherOwner, () => viewModel.IsVersionOk = versionOK); Debug.WriteLine("Is my Evernote API version up to date? " + versionOK); if (!versionOK) { return; } // Get the URL used to interact with the contents of the user's account // When your application authenticates using OAuth, the NoteStore URL will // be returned along with the auth token in the final OAuth request. // In that case, you don't need to make this call. String noteStoreUrl = userStore.getNoteStoreUrl(authToken); TTransport noteStoreTransport = new THttpClient(new Uri(noteStoreUrl)); TProtocol noteStoreProtocol = new TBinaryProtocol(noteStoreTransport); NoteStore.Client noteStore = new NoteStore.Client(noteStoreProtocol); // Listing all the user's notebook List <Notebook> notebooks = noteStore.listNotebooks(authToken); Debug.WriteLine("Found " + notebooks.Count + " notebooks:"); InvokeOnUIThread(dispatcherOwner, () => { foreach (var notebook in notebooks) { viewModel.Notebooks.Add(notebook); } }); // Find the default notebook Notebook defaultNotebook = notebooks.Single(notebook => notebook.DefaultNotebook); // Printing the names of the notebooks foreach (Notebook notebook in notebooks) { Debug.WriteLine(" * " + notebook.Name); } // Listing the first 10 notes in the default notebook NoteFilter filter = new NoteFilter { NotebookGuid = defaultNotebook.Guid }; NoteList notes = noteStore.findNotes(authToken, filter, 0, 10); InvokeOnUIThread(dispatcherOwner, () => { foreach (var note in notes.Notes) { viewModel.Notes.Add(note); } }); foreach (Note note in notes.Notes) { Debug.WriteLine(" * " + note.Title); } // Creating a new note in the default notebook Debug.WriteLine("Creating a note in the default notebook: " + defaultNotebook.Name); Note newNote = new Note { NotebookGuid = defaultNotebook.Guid, Title = "Test note from EDAMTest.cs", Content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<!DOCTYPE en-note SYSTEM \"http://xml.evernote.com/pub/enml2.dtd\">" + "<en-note>Here's an Evernote test note<br/>" + "</en-note>" }; Note createdNote = noteStore.createNote(authToken, newNote); ShowMessage(dispatcherOwner, "Successfully created new note with GUID: " + createdNote.Guid); }
public static void Main(string[] args) { // Real applications authenticate with Evernote using OAuth, but for the // purpose of exploring the API, you can get a developer token that allows // you to access your own Evernote account. To get a developer token, visit // https://sandbox.evernote.com/api/DeveloperToken.action String authToken = "your developer token"; if (authToken == "your developer token") { Console.WriteLine("Please fill in your developer token"); Console.WriteLine("To get a developer token, visit https://sandbox.evernote.com/api/DeveloperToken.action"); return; } // Initial development is performed on our sandbox server. To use the production // service, change "sandbox.evernote.com" to "www.evernote.com" and replace your // developer token above with a token from // https://www.evernote.com/api/DeveloperToken.action String evernoteHost = "sandbox.evernote.com"; Uri userStoreUrl = new Uri("https://" + evernoteHost + "/edam/user"); TTransport userStoreTransport = new THttpClient(userStoreUrl); TProtocol userStoreProtocol = new TBinaryProtocol(userStoreTransport); UserStore.Client userStore = new UserStore.Client(userStoreProtocol); bool versionOK = userStore.checkVersion("Evernote EDAMTest (C#)", Evernote.EDAM.UserStore.Constants.EDAM_VERSION_MAJOR, Evernote.EDAM.UserStore.Constants.EDAM_VERSION_MINOR); Console.WriteLine("Is my Evernote API version up to date? " + versionOK); if (!versionOK) { return; } // Get the URL used to interact with the contents of the user's account // When your application authenticates using OAuth, the NoteStore URL will // be returned along with the auth token in the final OAuth request. // In that case, you don't need to make this call. String noteStoreUrl = userStore.getNoteStoreUrl(authToken); TTransport noteStoreTransport = new THttpClient(new Uri(noteStoreUrl)); TProtocol noteStoreProtocol = new TBinaryProtocol(noteStoreTransport); NoteStore.Client noteStore = new NoteStore.Client(noteStoreProtocol); // List all of the notebooks in the user's account List <Notebook> notebooks = noteStore.listNotebooks(authToken); Console.WriteLine("Found " + notebooks.Count + " notebooks:"); foreach (Notebook notebook in notebooks) { Console.WriteLine(" * " + notebook.Name); } Console.WriteLine(); Console.WriteLine("Creating a note in the default notebook"); Console.WriteLine(); // To create a new note, simply create a new Note object and fill in // attributes such as the note's title. Note note = new Note(); note.Title = "Test note from EDAMTest.cs"; // To include an attachment such as an image in a note, first create a Resource // for the attachment. At a minimum, the Resource contains the binary attachment // data, an MD5 hash of the binary data, and the attachment MIME type. It can also // include attributes such as filename and location. ImageConverter converter = new ImageConverter(); byte[] image = (byte[])converter.ConvertTo(Resources.enlogo, typeof(byte[])); byte[] hash = new MD5CryptoServiceProvider().ComputeHash(image); Data data = new Data(); data.Size = image.Length; data.BodyHash = hash; data.Body = image; Resource resource = new Resource(); resource.Mime = "image/png"; resource.Data = data; // Now, add the new Resource to the note's list of resources note.Resources = new List <Resource>(); note.Resources.Add(resource); // To display the Resource as part of the note's content, include an <en-media> // tag in the note's ENML content. The en-media tag identifies the corresponding // Resource using the MD5 hash. string hashHex = BitConverter.ToString(hash).Replace("-", "").ToLower(); // The content of an Evernote note is represented using Evernote Markup Language // (ENML). The full ENML specification can be found in the Evernote API Overview // at http://dev.evernote.com/documentation/cloud/chapters/ENML.php note.Content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<!DOCTYPE en-note SYSTEM \"http://xml.evernote.com/pub/enml2.dtd\">" + "<en-note>Here's the Evernote logo:<br/>" + "<en-media type=\"image/png\" hash=\"" + hashHex + "\"/>" + "</en-note>"; // Finally, send the new note to Evernote using the createNote method // The new Note object that is returned will contain server-generated // attributes such as the new note's unique GUID. Note createdNote = noteStore.createNote(authToken, note); Console.WriteLine("Successfully created new note with GUID: " + createdNote.Guid); }