EverNoteããAPIãæä¾ããã¦ããã®ãæè¿ç¥ãã¾ãã¦æ©é使ã£ã¦ã¿ã¾ããã
ï¼å®éã¯å¤§ååããæä¾ããã¦ããã¿ããã§ããï½ï¼
ã¾ãã¯æºåã
EverNote APIã¯å©ç¨ããéã«ãã¾ãç³è«ãå¿
è¦ã¨ãªãã¾ãã
以ä¸ã®ãã¼ã¸ããç³è«ãã¾ãã
質åã®å
容ã®ã¨ããã«ãã©ããªç®çã§APIã使ããããè¨è¿°ãã¦éä¿¡ãã¾ãã
æ©ãã£ããã1å¶æ¥æ¥ãããã§ãã¼ã¨ãã¹ã¯ã¼ããå±ãã¾ãã
APIãã¼ãå±ããããhttps://sandbox.evernote.com/ ã§æ°ãã«ã¢ã«ã¦ã³ãã
ä½æãã¾ããæ£è¦ã®EverNoteã®æ¹ã§å©ç¨ãã¦ããã¢ã«ã¦ã³ãåã¨åãååã§ã
ä½æã§ãã¾ãã
å¾ã¯ãhttp://www.evernote.com/about/developer/api/ ããAPIæ¬ä½ããã¦ã³ãã¼ããã¾ãã
APIã®ä¸ã«ã¯ãåè¨èªç¨ã®ãµã³ãã«ã¨ã©ã¤ãã©ãªãå
¥ã£ã¦ãã¾ãã
APIèªä½ã¯ãApache Thriftãç¨ãã¦ä½æããã¦ãã¾ãã
Javaã¨ãã®å ´åã¯ãæåããjarãã¡ã¤ã«ã¨ããç¨æããã¦ããã®ã§ãã
C#ã®å ´åã¯ãdllãèªåã§ã³ã³ãã¤ã«ããªãã¨ããã¾ããã»ã»ã»ã
APIã®ãã©ã«ãã®ä¸ã®
src/csharp/Thrift/
ã®ä¸ã«Visual Studioã½ãªã¥ã¼ã·ã§ã³ãã¡ã¤ã«ãåå¨ãã¾ãã
ããã§ãã£ãã¨ã³ã³ãã¤ã«ãããã¨æã£ãããéãã¾ããã§ããã»ã»ã»ã»ã
ãæå¹ãªã½ãªã¥ã¼ã·ã§ã³ãã¡ã¤ã«ã§ã¯ããã¾ãããã£ã¦ã¨ã©ã¼ãåºã¾ãã
ããããªãã®ã§ãèªåã§VSã½ãªã¥ã¼ã·ã§ã³ãä½ã£ã¦ä¸ã®ã½ã¼ã¹ã
æ¾ãè¾¼ãã§ã³ã³ãã¤ã«ãããã§ãã£ã¨DLLãæã«å
¥ãã¾ããã
ï¼ããã¤ãè¦åãã§ãã®ã§ã¡ããã¡ããä¿®æ£ï¼
ãµã³ãã«ãè¦ãªããããã¹ãå¦çãè¨è¿°ã
C#ã®ãµã³ãã«ã¯Monoã§ä½æãã¦ããã£ã½ãã§ãã
C#ã®ãµã³ãã«ã½ã¼ã¹ã®ãããé¨åã«ãgmcsã§ã³ã³ãã¤ã«ããä¾ãè¨è¿°ããã¦ããã¾ãã
ã§ããã£ã¨ä½¿ãæ¹ã§ããå©ç¨ããã«ã¯ãã¾ãé£ãããªãã§ãã
以ä¸ãè¦ç¹é¨åãè²¼ãä»ãã¦ããã¾ãã
ã¾ãã¯ããã¼ã¸ã§ã³ãã§ãã¯é¨åã
å©ç¨ãã¦ããAPIã®ãã¼ã¸ã§ã³ããã§ãã¯ãã¾ãã
var userName = "xxxxx"; var password = "xxxxx"; var consumerKey = "xxxxx"; var consumerSecret = "xxxxx"; var defaultNotebookName = "xxxxx"; var host = @"https://sandbox.evernote.com"; var userStoreUrl = string.Format("{0}/edam/user", host); TTransport userStoreTransport = new THttpClient(userStoreUrl); TProtocol userStoreProtocol = new TBinaryProtocol(userStoreTransport); UserStore.Client userStore = new UserStore.Client(userStoreProtocol); bool versionOK = userStore.checkVersion( "EverNote Api Version Check", Evernote.EDAM.UserStore.Constants.EDAM_VERSION_MAJOR, Evernote.EDAM.UserStore.Constants.EDAM_VERSION_MINOR ); Assert.IsTrue(versionOK);
APIå ¨ä½ã§ãããããã¿ã¼ã³ã¨ãã¦
Transportãåå¾ãã¦ã次ã«Protocolãåå¾ãæå¾ã«ç®çã®æ å ±ãæã¤xxStoreãåå¾
ããã¨ããæµãã«ãªã£ã¦ãã¾ãã
ãã¼ãã®å ´åã¯ãæçµçã«NoteStoreãåå¾ãã¦ãã¼ãæ
å ±ãå¦çãã¾ãã
次ã«ãæ¥ç¶ï¼èªè¨¼ï¼ãã¾ãã
èªè¨¼ã失æããå ´åã¯ä¾å¤ãçºçãã¾ãã
AuthenticationResult authResult = null; try { authResult = userStore.authenticate(userName, password, consumerKey, consumerSecret); } catch (EDAMUserException ex) { Console.WriteLine("{0}, {1}", ex.ErrorCode, ex.Parameter); Assert.Fail(); }
èªè¨¼ãæåããããå¾ã¯å¿
è¦ãªæ
å ±ãéãã¦
ãã¼ããæãã¾ããã¾ãã¯ã¦ã¼ã¶æ
å ±ãåå¾ã
User user = authResult.User;
Assert.AreEqual<string>(userName, user.Username);
String authToken = authResult.AuthenticationToken;
ä¸è¨ã§åå¾ãã¦ããèªè¨¼ãã¼ã¯ã³(AuthenticationToken)ããããéè¦ã§ãã
ä½ãã®æ
å ±ãåå¾ããéã«ããããå¿
è¦ã¨ãªãã¾ãã
ãããããã¼ãã®åå¾.
String noteStoreUrl = string.Format("{0}/edam/note/{1}", host, user.ShardId); TTransport noteStoreTransport = new THttpClient(noteStoreUrl); TProtocol noteStoreProtocol = new TBinaryProtocol(noteStoreTransport); NoteStore.Client noteStore = new NoteStore.Client(noteStoreProtocol); List<Notebook> notebooks = noteStore.listNotebooks(authToken);
user.ShardIdã¯ãuser.SharedIdãããªãã®ãã¨æãã¤ã¤ã»ã»ã»ã
EverNoteã«ã¯ãå¿
ãä¸ã¤ã¯ãã¼ãããã¯ãåå¨ãã¾ããï¼Default Notebook)
ä½ãè¨å®ãã¦ããªãå ´åã§ããnotebooksã®ã«ã¦ã³ãã¯1ã¨ãªãã¾ãã
å®éã«ãã¼ããç»é²ãã¦ã¿ã¾ãã
ãµã³ãã«ä¸¸ã±ãããªã®ã§ãç»åãã¡ã¤ã«ä»ãã§ãã¼ããæ°è¦ç»é²ãã¾ãã
byte[] image = (byte[]) new ImageConverter().ConvertTo(Properties.Resources.enlogo, typeof(byte[])); byte[] hash = new MD5CryptoServiceProvider().ComputeHash(image); string hashHex = BitConverter.ToString(hash).Replace("-", "").ToLower(); 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; Note note = new Note(); note.NotebookGuid = defaultNotebook.Guid; note.Title = "Test note from EverNoteApiTest"; note.Content = GetContent(hashHex); note.Created = (long) (DateTime.Now - new DateTime(1970, 1, 1)).TotalMilliseconds; note.Updated = note.Created; note.Active = true; note.Resources = new List<Resource>(); note.Resources.Add(resource); Note createdNote = noteStore.createNote(authToken, note); private static string GetContent(string hashHex) { return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<!DOCTYPE en-note SYSTEM \"http://xml.evernote.com/pub/enml.dtd\">" + "<en-note>Here's the Evernote logo:<br/>" + "<en-media type=\"image/png\" hash=\"" + hashHex + "\"/>" + "</en-note>"; }
æµãã¨ãã¦ã¯ã
- æ·»ä»ãã¡ã¤ã«ãããå ´å
- Dataã¤ã³ã¹ã¿ã³ã¹ãä½æ
- å±æ§ãè¨å® (ãã¼ã¿ã¯ãã¤ãé åã§è¨å®ï¼
- Resourceã¤ã³ã¹ã¿ã³ã¹ãä½æãã¦Dataãè¨å®
- Noteã¤ã³ã¹ã¿ã³ã¹ãä½æ
- åå±æ§ãè¨å®
- æ¬æã¯XMLå½¢å¼ã§è¨å®ããã
- æ·»ä»ãã¡ã¤ã«ã¯ãResourcesããããã£ã«ãªã¹ãã§è¨å®ããã
- æå¾ã«noteStore.createNoteã§ç»é²
ã¨ãªãã¾ãã
次ã¯æ´æ°ã
Note n = noteStore.getNote(authToken, createdNote.Guid, true, true, true, true); n.Title = "Update From EverNoteApiTest"; note.Updated = (long)(DateTime.Now - new DateTime(1970, 1, 1)).TotalMilliseconds; noteStore.updateNote(authToken, n);
åããããªæãã§ãããã¼ããåå¾ãã¦å±æ§ãå¤æ´ã
ãã¼ããåå¾ããéã«ã¯ããã¼ã¯ã³ã¨ãã¼ãã®GUIDãå¿
è¦ã«ãªãã¾ãã
æå¾ã«updateNoteã§æ´æ°ãã¾ãã
次ã«åé¤ã
noteStore.deleteNote(authToken, createdNote.Guid);
åé¤ããããã¼ãã¯ãActiveããããã£ãfalseã¨è¨å®ããã¾ãã
ã¾ããã®å ´åã®åé¤ã¯ãç©çåé¤ã§ã¯ãªãã¦EverNoteä¸ã®ããã¿ç®±ãã«ç§»åããã¾ãã
ã§ãæå¾ã«æ¤ç´¢ã§ãã
æ¤ç´¢ã¯ãNoteFilterãä½æãã¦æ¤ç´¢ãã¾ãã
NoteFilter filter = new NoteFilter(); filter.Words = "EverNoteApiTest"; filter.NotebookGuid = defaultNotebook.Guid; filter.Inactive = false; NoteCollectionCounts findNoteCount = noteStore.findNoteCounts(authToken, filter, false); NoteList findNotes = noteStore.findNotes(authToken, filter, 0, 1000);
findNoteCountsã§ãåè´ãããã¼ãã®æ°ã
findNotesã§ãåè´ãããã¼ããåå¾ã§ãã¾ãã
ã§ããç§ã®ç°å¢ã§è©¦ãã¦ã¿ãã¨ãã
NoteFilterã®Inactiveã«æ示çã«false (åé¤ããããã¼ããæ¤ç´¢å¯¾è±¡ã¨ããªã)ã¨è¨å®ãã¦ããã®ã«
æ¤ç´¢ããã¨åé¤ããããã¼ãã¾ã§å«ã¾ãã¦ãã¾ãããããã°ãªã®ããªãã»ã»ã»ä½¿ãæ¹ããããã®ãã
ç¥ã£ã¦ããæ¹ããã£ããã£ããæãã¦ãã ããã m(_ _)m
ï¼ã¨ããããåãåããã¦ã¿ã¾ããï¼
æå¾ã«ä¸è¨ã®ã½ã¼ã¹ã®å ¨ä½çã§ãã
using System; using System.Collections.Generic; using System.Drawing; using System.Linq; using System.Security.Cryptography; using Evernote.EDAM.Error; using Evernote.EDAM.NoteStore; using Evernote.EDAM.Type; using Evernote.EDAM.UserStore; using Microsoft.VisualStudio.TestTools.UnitTesting; using Thrift.Protocol; using Thrift.Transport; namespace EverNoteApiTest { [TestClass] public class UnitTest1 { [TestMethod] public void TestMethod1() { var userName = "xxxxx"; var password = "xxxxx"; var consumerKey = "xxxxx"; var consumerSecret = "xxxxx"; var defaultNotebookName = "xxxxx"; var host = @"https://sandbox.evernote.com"; var userStoreUrl = string.Format("{0}/edam/user", host); TTransport userStoreTransport = new THttpClient(userStoreUrl); TProtocol userStoreProtocol = new TBinaryProtocol(userStoreTransport); UserStore.Client userStore = new UserStore.Client(userStoreProtocol); bool versionOK = userStore.checkVersion( "EverNote Api Version Check", Evernote.EDAM.UserStore.Constants.EDAM_VERSION_MAJOR, Evernote.EDAM.UserStore.Constants.EDAM_VERSION_MINOR ); Assert.IsTrue(versionOK); AuthenticationResult authResult = null; try { authResult = userStore.authenticate(userName, password, consumerKey, consumerSecret); } catch (EDAMUserException ex) { Console.WriteLine("{0}, {1}", ex.ErrorCode, ex.Parameter); Assert.Fail(); } User user = authResult.User; Assert.AreEqual<string>(userName, user.Username); String authToken = authResult.AuthenticationToken; String noteStoreUrl = string.Format("{0}/edam/note/{1}", host, user.ShardId); TTransport noteStoreTransport = new THttpClient(noteStoreUrl); TProtocol noteStoreProtocol = new TBinaryProtocol(noteStoreTransport); NoteStore.Client noteStore = new NoteStore.Client(noteStoreProtocol); List<Notebook> notebooks = noteStore.listNotebooks(authToken); Assert.AreEqual<int>(1, notebooks.Count); Notebook defaultNotebook = null; foreach (Notebook notebook in notebooks) { if (notebook.DefaultNotebook) { defaultNotebook = notebook; } } Assert.IsNotNull(defaultNotebook); Assert.AreEqual<string>(defaultNotebookName, defaultNotebook.Name); byte[] image = (byte[]) new ImageConverter().ConvertTo(Properties.Resources.enlogo, typeof(byte[])); byte[] hash = new MD5CryptoServiceProvider().ComputeHash(image); string hashHex = BitConverter.ToString(hash).Replace("-", "").ToLower(); 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; Note note = new Note(); note.NotebookGuid = defaultNotebook.Guid; note.Title = "Test note from EverNoteApiTest"; note.Content = GetContent(hashHex); note.Created = (long) (DateTime.Now - new DateTime(1970, 1, 1)).TotalMilliseconds; note.Updated = note.Created; note.Active = true; note.Resources = new List<Resource>(); note.Resources.Add(resource); Note createdNote = noteStore.createNote(authToken, note); Assert.AreEqual<string>("Test note from EverNoteApiTest", createdNote.Title); Assert.IsTrue(createdNote.Active); var bodyHash = createdNote.Resources.First().Data.BodyHash; for (int i = 0; i < bodyHash.Length; i++) { Assert.AreEqual<byte>(hash[i], bodyHash[i]); } Note n = noteStore.getNote(authToken, createdNote.Guid, true, true, true, true); n.Title = "Update From EverNoteApiTest"; note.Updated = (long)(DateTime.Now - new DateTime(1970, 1, 1)).TotalMilliseconds; noteStore.updateNote(authToken, n); n = noteStore.getNote(authToken, createdNote.Guid, true, true, true, true); Assert.AreEqual<string>("Update From EverNoteApiTest", n.Title); //NoteFilter filter = new NoteFilter(); //filter.Words = "EverNoteApiTest"; //filter.NotebookGuid = defaultNotebook.Guid; //filter.Inactive = false; //NoteCollectionCounts findNoteCount = noteStore.findNoteCounts(authToken, filter, false); //Assert.AreEqual<int>(1, findNoteCount.NotebookCounts[defaultNotebook.Guid]); //NoteList findNotes = noteStore.findNotes(authToken, filter, 0, 1000); //Assert.AreEqual<int>(1, findNotes.Notes.Count); //Assert.AreEqual<string>(n.Guid, findNotes.Notes.First().Guid); noteStore.deleteNote(authToken, createdNote.Guid); n = noteStore.getNote(authToken, createdNote.Guid, true, true, true, true); Assert.IsFalse(n.Active); } private static string GetContent(string hashHex) { return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<!DOCTYPE en-note SYSTEM \"http://xml.evernote.com/pub/enml.dtd\">" + "<en-note>Here's the Evernote logo:<br/>" + "<en-media type=\"image/png\" hash=\"" + hashHex + "\"/>" + "</en-note>"; } } }
ãããªæãã§ãã
æã£ã¦ãããã使ããããAPIã§ãããã¾ã ã¾ã 試ãã¦ããªãAPIã¯ãã£ã±ãããã®ã§
ã¡ããã¡ããåå¼·ãã¦ã¿ã¾ãã(ãã¼ã¿ã®åæã¨ãï¼
æè§ç°å¢æ§ç¯ããã®ã§ãè¨å®ããVisualStudioããã¸ã§ã¯ãã¨
ãã«ãããDLLã以ä¸ãããã¦ã³ãã¼ãã§ããããã«ãã¦ãã¾ãã
ã¦ã£ã¨ãæ©ã試ãã¦ã¿ããæ¹ã¯ã©ããã
(ããã¸ã§ã¯ãã¯VisualStudio 2010å½¢å¼ã§ããããã«ãã¿ã¼ã²ããã¯3.5ã«ãã¦ããã¾ããï¼
- VisualStudio 2010ããã¸ã§ã¯ãã¨DLLãã¡ã¤ã«
ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼
éå»ã®è¨äºã«ã¤ãã¦ã¯ã以ä¸ã®ãã¼ã¸ãããåç
§ä¸ããã
- ããããåå¿é²æ¥è¨ã¾ã¨ã