2010/11/28

Evernote API Keyが送られてきていたので、Pythonのサンプルコードを試してみました。



昨日申し込みをしていた Evernote API Keyが送られてきていました。


早速、Pythonのサンプルコードに「consumer key」「consumer secret」を設定して試してみました。evernote-api-1.17/lib/python の階層にて EDAMTest.pyをパラメータ付きで起動します。
python EDAMTest.py username password
を試します。
  File "EDAMTest_101128_01.py", line 59
    except Errors.EDAMUserException as e:
                                     ^
SyntaxError: invalid syntax
というエラーが起きます。動作させているPython2.5に合わせて、エラー処理の書式を変更します。
except Errors.EDAMUserException, e:
これで、この箇所のエラーはスルーできます。次に下記のエラーが表示されました。
Traceback (most recent call last):
  File "EDAMTest_101128_01.py", line 16, in 
    import thrift.protocol.TBinaryProtocol as TBinaryProtocol
ImportError: No module named thrift.protocol.TBinaryProtocol
thriftに関するパスが通っていないようです。

evernote-api-1.17/lib/pythonにあった
  • evernote
  • thrift
の2つのモジュールをPYTHONPATHの通っているところへコピーしました。

このエラーはスルー。次に下記のエラーが表示されました。
Is my EDAM protocol version up to date?  True

Authentication failed (parameter: username errorCode: INVALID_AUTH)
You must authenticate using a username and password from sandbox.evernote.com
Note that your production Evernote account will not work on sandbox.evernote.com

You must register for a separate test account at https://sandbox.evernote.com/Re
gistration.action
Evernote APIは、いきなり本番環境で動作させるのではなく、sandbox(練習場)で操作方法を確認してから、本環境に移行するようです。

現在持っているEvernoteアカウントとは別に、sandbox用のEvernoteアカウントを作成します。

https://sandbox.evernote.com/Registration.action


sandbox用に作成したEvernoteアカウント、パスワードを設定して、再度試します。
python EDAMTest.py username password
Is my EDAM protocol version up to date?  True

Authentication was successful for  
Authentication token =  ********************************************************
**********************************
Found  1  notebooks:
  *   ***************

Creating a new note in default notebook:   ***************

Created note:  Note(contentHash='\xcer\x00f\xff\x94\x14<\x1d\xb7\xfa\xf8\x83f\xb
9b', updated=1290914178000L, created=1290914178000L, deleted=None, contentLength
=220, title='Test note from EDAMTest.py', notebookGuid='8cba458f-ec76-4eb1-8627-
0a595cc5fdf4', content=None, tagNames=None, updateSequenceNum=3, tagGuids=None,
active=True, attributes=NoteAttributes(sourceURL=None, author=None, altitude=Non
e, longitude=None, source=None, sourceApplication=None, latitude=None, subjectDa
te=None), guid='56323033-dd88-45fa-aed0-b7d9c93a7727', resources=[Resource(noteG
uid='56323033-dd88-45fa-aed0-b7d9c93a7727', height=60, width=60, alternateData=N
one, mime='image/png', updateSequenceNum=4, duration=None, attributes=ResourceAt
tributes(recoType=None, sourceURL=None, cameraMake=None, timestamp=None, altitud
e=None, clientWillIndex=None, longitude=None, fileName=None, attachment=None, la
titude=None, cameraModel=None), guid='2906afa4-1f05-46f2-98c8-fce6337cee90', dat
a=Data(body=None, bodyHash='\xa5O\xe8\xbc\xd1F\xe2\n\x8aWB\x83EXT<', size=6035),
 active=True, recognition=Data(body='\nOCTYPE recoIndex PUBLIC "SYSTEM" "http://xml.evernote.com/pub/recoIndex.dtd">
coIndex docType="picture" objType="image" objID="a54fe8bcd146e20a8a5742834558543
c" engineVersion="3.0.17.12" recoType="service" lang="ja" objWidth="60" objHeigh
t="60"/>\n', bodyHash='\x91G\x01\xa5\x11\\Xw\xca\xc1\x00"\x9d\xf3\x16Y', size=29
1))])
Evernote APIを通してアクセスできました。

0 件のコメント:

人気の投稿 (過去 30 日間)