Documentation - Evernote Developers
Perlでいいかなぁと思ったけど公式ドキュメントが不親切なのでPythonにする。
Evernote Cloud API — Python Quick-start Guide - Evernote Developers
getting startedのドキュメントによると、まずは
次にSDKをインストールする。
$ pip install evernote
を実行するとエラーになる・・・
GitHub - evernote/evernote-sdk-python: Evernote SDK for Python
GitHub - evernote/evernote-sdk-python3: Testing the Evernote Cloud API for Python 3
This is a test SDK! The official Evernote SDK for Python doesn't support Python 3 yet; this repository is an experiment as we try to migrate.
えぇ・・・。
今の時代はPython3だと聞いたのでPython2とか入れてないんだけど。
http://dogwood.skr.jp/blog/2013/12/426/
なるほどね〜
というわけでCygwinのPythonをアンインストールしてWindows版にする。
$ py -2 -m pip install evernote
うまくいった。
一通り環境はできたのでサンプルコードを書きたい。が、その前にアクセストークンを取得しておく。
Developer Tokens - Evernote Developers
sandboxのdeveloper tokenはすぐに取得できるけど、productionのdeveloper tokenは "Update: the creation of developer tokens is temporarily disabled." などというメッセージが出て取得できないようになってる。
仕方がないのでsupportのページからAPI keyのactivation申請をする
に行くと"Activate an API Key"というボタンがあるので適当に入力する。
How do I copy my API key from Sandbox to www (production)?
This process is called key activation. To activate your API key on Evernote’s production servers, file a key activation request using this form. Once we’ve determined that your integration fulfills all of the requirements of a production application, your key will be activated within 1?2 business days. You’ll be notified when your key has been activated (or if there’s an issue with your application that needs to be addressed).
申請項目のpermissionというのがよく分からんかったけど、多分ここのページに乗ってる意味でのpermissionなんだと思う。
API Key Permissions - Evernote Developers
とりあえず "Full access" permissionを下さいな、と書いておいた。
サンプルコード
ノートブックとノートブック内のノートのリストを表示する。
from evernote.api.client import EvernoteClient from evernote.edam.notestore.ttypes import NoteFilter, NotesMetadataResultSpec dev_token = "<your developer token>" client = EvernoteClient(token=dev_token) userStore = client.get_user_store() user = userStore.getUser() print "username : " + user.username + "\n" offset = 0 max_notes = 10 noteStore = client.get_note_store() notebooks = noteStore.listNotebooks() for n in notebooks: print "* " + n.name filter = NoteFilter(notebookGuid=n.guid) result_spec = NotesMetadataResultSpec(includeTitle=True) result_list = noteStore.findNotesMetadata(dev_token, filter, offset, max_notes, result_spec) for note in result_list.notes: print "\t- %s" % note.title
$ py -2 a.py username : kobayashi01234 * <Inbox> * プロジェクトその1 * testbook1 - testnote001
なるほどね。
シンプルにノートブック名を指定してノート一覧を取得できればいいのだけど、そういう機能はないっぽい。
Get a notebook by name and its notes - Evernote API Discussion - Evernote User Forum
追記
API keyのactivation mailが6/3朝(USだとすると現地時間では6/2夕方)くらいに来ていた。結構すぐに来るものなんだな。そして適当に申請してもだいじょうぶそうw