Christopher Metts

✔ Creating note in shared notebook

12 posts in this topic

I need help creating a new note in a shared notebook. So far, I am using the following:

 

 

//////////

 

 

theSharedNotebook = note_store.authenticateToSharedNotebook(theShareToken, dev_token)

 

linked_note_store = client.get_shared_note_store(theSharedNotebook)

 

 

note = linked_note_store.createNote(note)

 

/////////

 

 

But I am getting the following error message:

 

AttributeError: 'AuthenticationResult' object has no attribute 'shareKey'

Share this post


Link to post

So if I understand what you want to do :

 

User A shared a notebook with User B and gave B write permissions so that B is allowed to create notes in this notebook.

Now you want B to add a note to the shared notebook through the API. 

If this is what you want to achieve, here's a way :

 

# First, authenticate to the shared notebook :auth_result = note_store.authenticateToSharedNotebook(shareKey, auth_token)# Next, create your note as you would do for a "normal" notebook:note = Types.Note()note.title = "Test note from EDAMTest.py"# Set the notebook guid as the sharedNotebook guid :note.notebookGuid = "03e54745-0fc3-4f69-8101-687babc5c330"# Create the note :created_note = note_store.createNote(auth_result.authenticationToken, note)

 

Hope this helps

Share this post


Link to post

I use the following code to get the shared notebook:

 

 

theSharedNotebookAuth = note_store.authenticateToSharedNotebook(theMDbotNotebookShareToken, dev_token)

theSharedNotebook = note_store.getSharedNotebookByAuth(theSharedNotebookAuth.authenticationToken)

logging.debug("the shared notebook: " + str(theSharedNotebook))

 

the log shows this as the shared notebook object:

 

the shared notebook: SharedNotebook(username='doctor', requireLogin=True, userId=406214, allowPreview=False, notebookModifiable=True, notebookGuid='1b306a08-c03e-4b4e-bd0f-83ea53e5abb2', shareKey='2d77-s1-056ce76886a32a32dd93e07a41ecc3a8-2', email='doctor@md-bot.com', serviceUpdated=1367850186000L, privilege=1, serviceCreated=1367849414000L, id=11639)

 

 

I then use this to create new note to in the sharednotebook:

 

 

note = Types.Note()

note.title = "I'm a test note!"

note.content = '<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd">'

note.content += '<en-note>Hello, world!</en-note>'

note.notebookGuid = theSharedNotebook.notebookGuid

note = note_store.createNote(note)

 

 

But I get the following error:

 

EDAMUserException: EDAMUserException(errorCode=3, parameter='authenticationToken')

 

 

Any ideas what I am doing wrong?

 

Thanks,

Chris

Share this post


Link to post

try 

 

note = note_store.createNote(theSharedNotebookAuth.authenticationToken, note)

 

(not tested)

 

Laurent

Share this post


Link to post

Using same note_store seems to work only on sandbox since the shardId would be different from the one that the shared note resides in.

 

On the sandbox, we have only one shard and that's the reason why your code works, I guess.

 

Use Client#get_shared_note_store as you tried first.

shared_note_store = client.get_shared_note_store(linked_notebook)

 

The argument is a LinkedNotebook object which you want to access.

Share this post


Link to post

Thank Kentaro, I was wondering why I wasn't having to do that. I am having problem with this though. I am using the following code to get the shared notebook:

 

 

note_store = client.get_note_store()

theSharedNotebookAuth = note_store.authenticateToSharedNotebook(theMDbotNotebookShareToken, dev_token)

theSharedNotebook = note_store.getSharedNotebookByAuth(theSharedNotebookAuth.authenticationToken)shared_note_store = client.get_shared_note_store(theSharedNotebook)

 

but I get the following error:

 

AttributeError: 'SharedNotebook' object has no attribute 'noteStoreUrl'

Share this post


Link to post

The argument is not SharedNotebook but LinkedNotebook.

Share this post


Link to post
ok, but as far as I know, the only way to access the linkedNotebook I want to work with is listLinkedNotebooks, and then iterate them looking for the one I want, I guess using a guid?

 

Is there a more direct way like you have for shared notebooks?

 

theSharedNotebookAuth = note_store.authenticateToSharedNotebook(theMDbotNotebookShareToken, dev_token)

theSharedNotebook = note_store.getSharedNotebookByAuth(theSharedNotebookAuth.authenticationToken)

Share this post


Link to post

How did you get a shareKey?  I guess "theMDbotNotebookShareToken" in your code is a shareKey of some notebook and to get the shareKey, you need to access LinkedNotebook first.

Share this post


Link to post

I got the shareKey earlier in the iOS app and saved it to the database. I could use that to get the linked notebook directly if there was a method for doing so. As it stands now, I have to iterate the list of linked notebooks each time I want to use it. Is there another approach?

 

I have it working, but it seems rather inefficient.

 

Thanks

Share this post


Link to post

Unfortunately, there's no method to get a specific LinkedNotebook directly.

 

By the way, If you also stored the noteStoreUrl value of the LinkedNotebook object, you could make NoteStore to call API.  Otherwise, you can't access the SharedNotebook object anyways (and that's why the method requires LinkedNotebook now).

http://dev.evernote.com/documentation/reference/Types.html#Struct_LinkedNotebook

 

It might be good to have some function to get sharedNoteStore without a LinkedNotebook object as you wrote so I'll think about it.  Meanwhile, if you have already stored shareKey and noteStoreUrl and don't want to iterate linked notebooks, I can propose some workaround if you want (that could not be a clean way though..).

 

Thank you for your feedback.

Share this post


Link to post