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

Get list of public notebooks given a username

python api userstore notestore auth authentication public shared notebook

  • Please log in to reply
1 reply to this topic

#1 occulens

occulens

  • Pip
  • Title: Member
  • Group: Members
  • 7 posts

Posted 26 November 2011 - 02:07 PM

Hi, I am trying to create a blog app built on evernote that basically allows you to view any public notebook in a more 'bloggy' form.

Assume I have the username of a Evernote user with 0 or more public notebooks. For example, my username is occulens. Given this username, is it possible to get a list of my public notebooks without authenticating? (assume we have username, consumerKey and consumerSecret, but nothing else)

What might this code look like? (python or psuedocode is preferred)

#2 occulens

occulens

  • Pip
  • Title: Member
  • Group: Members
  • 7 posts

Posted 26 November 2011 - 11:30 PM

OK, I got it figured out. Here's what I learned:

Given this username, is it possible to get a list of my public notebooks without authenticating? (assume we have username, consumerKey and consumerSecret, but nothing else)


Not quite. You can't get a list of someone's public notebooks based on their username. This may be a choice that evernote made -- to protect people's privacy. So, you will also need the name of the public notebook. From there you can read all the notebook data.

And here's the python code:


#This code was adapted from the API sample file EDAMTest.py
#You'll need a public notebook somwhere in the sandbox. You'll also need to set the notebook_name to the name of your public notebook.

import sys
import hashlib
import binascii
import time
import thrift.protocol.TBinaryProtocol as TBinaryProtocol
import thrift.transport.THttpClient as THttpClient
import evernote.edam.userstore.UserStore as UserStore
import evernote.edam.userstore.constants as UserStoreConstants
import evernote.edam.notestore.NoteStore as NoteStore
import evernote.edam.notestore.ttypes as NoteStoreTypes
import evernote.edam.type.ttypes as Types
import evernote.edam.error.ttypes as Errors

# NOTE: You must change the consumer key and consumer secret to the
#	   key and secret that you received from Evernote
#
consumerKey = "YOUR KEY HERE"
consumerSecret = "YOUR SECRET HERE"

evernoteHost = "sandbox.evernote.com"
userStoreUri = "https://" + evernoteHost + "/edam/user"
noteStoreUriBase = "https://" + evernoteHost + "/edam/note/"

userStoreHttpClient = THttpClient.THttpClient(userStoreUri)
userStoreProtocol = TBinaryProtocol.TBinaryProtocol(userStoreHttpClient)
userStore = UserStore.Client(userStoreProtocol)

versionOK = userStore.checkVersion("Python EDAMTest",
								   UserStoreConstants.EDAM_VERSION_MAJOR,
								   UserStoreConstants.EDAM_VERSION_MINOR)

#check EDAM protocol version
print "Is my EDAM protocol version up to date? ", str(versionOK)
print ""
if not versionOK:
    print "No. Exiting."
    exit(1)

#get basic user info
user = userStore.getPublicUserInfo('occulens')

noteStoreUri =  noteStoreUriBase + user.shardId
noteStoreHttpClient = THttpClient.THttpClient(noteStoreUri)
noteStoreProtocol = TBinaryProtocol.TBinaryProtocol(noteStoreHttpClient)
noteStore = NoteStore.Client(noteStoreProtocol)

notebook_name = 'blog'

try:
    notebook = noteStore.getPublicNotebook(user.userId, notebook_name)
except Errors.EDAMNotFoundException:
    print "we couldn't find the public notebook " + notebook_name
    exit(1)

note_filter = NoteStoreTypes.NoteFilter(notebookGuid=notebook.guid)
notelist = noteStore.findNotes('', note_filter, 0, 10)

for note in notelist.notes:
    print 'guid: ' + str(note.guid) + ' title: ' + note.title

print 'done!'






Also tagged with one or more of these keywords: python, api, userstore, notestore, auth, authentication, public, shared, notebook

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Clip to Evernote