Jump to content

Welcome! You're currently a Guest.

If you'd like to join in the Discussion, or access additional features in our forums, please sign in with your Evernote Account here. Have an Evernote Account but forgot your password? Reset it! Don't have an account yet? Create One! You'll need to set your Display Name before your first post.

Photo

✔ Creating note in shared notebook

python

  • Please log in to reply
11 replies to this topic

#1 Christopher Metts

Christopher Metts

  • PipPip
  • Title: Alliance Lackey
  • Group: Members
  • 50 posts

Posted 05 May 2013 - 12:52 AM

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'



#2 Laurent Sarrazin

Laurent Sarrazin

  • Title: Browncoat
  • Group: Developer Evangelist
  • 339 posts

Posted 05 May 2013 - 09:50 PM

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



#3 Christopher Metts

Christopher Metts

  • PipPip
  • Title: Alliance Lackey
  • Group: Members
  • 50 posts

Posted 06 May 2013 - 02:51 PM

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



#4 Laurent Sarrazin

Laurent Sarrazin

  • Title: Browncoat
  • Group: Developer Evangelist
  • 339 posts

Posted 06 May 2013 - 02:59 PM

try 

 

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

 

(not tested)

 

Laurent



#5 Christopher Metts

Christopher Metts

  • PipPip
  • Title: Alliance Lackey
  • Group: Members
  • 50 posts

Posted 06 May 2013 - 03:10 PM

That did it! Thanks!



#6 Kentaro

Kentaro

  • Title: Browncoat
  • Group: Evernote Employee
  • 265 posts

Posted 09 May 2013 - 01:37 AM

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.



#7 Christopher Metts

Christopher Metts

  • PipPip
  • Title: Alliance Lackey
  • Group: Members
  • 50 posts

Posted 09 May 2013 - 12:37 PM

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'



#8 Kentaro

Kentaro

  • Title: Browncoat
  • Group: Evernote Employee
  • 265 posts

Posted 09 May 2013 - 05:48 PM

The argument is not SharedNotebook but LinkedNotebook.



#9 Christopher Metts

Christopher Metts

  • PipPip
  • Title: Alliance Lackey
  • Group: Members
  • 50 posts

Posted 09 May 2013 - 07:23 PM

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)


#10 Kentaro

Kentaro

  • Title: Browncoat
  • Group: Evernote Employee
  • 265 posts

Posted 09 May 2013 - 09:13 PM

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.



#11 Christopher Metts

Christopher Metts

  • PipPip
  • Title: Alliance Lackey
  • Group: Members
  • 50 posts

Posted 09 May 2013 - 09:18 PM

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



#12 Kentaro

Kentaro

  • Title: Browncoat
  • Group: Evernote Employee
  • 265 posts

Posted 09 May 2013 - 09:58 PM

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...._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.







0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Clip to Evernote