Skip to content

Instantly share code, notes, and snippets.

@lupo49
Created January 1, 2012 14:35
Show Gist options
  • Save lupo49/1547487 to your computer and use it in GitHub Desktop.
Save lupo49/1547487 to your computer and use it in GitHub Desktop.
Evernote - Dump content of Notes through PHP
<?php
// API documentation: https://www.evernote.com/about/developer/api/ref/
define("NE", "<br />");
require_once("autoload.php");
require_once("Thrift.php");
require_once("transport/TTransport.php");
require_once("transport/THttpClient.php");
require_once("protocol/TProtocol.php");
require_once("protocol/TBinaryProtocol.php");
require_once("packages/Errors/Errors_types.php");
require_once("packages/Types/Types_types.php");
require_once("packages/UserStore/UserStore.php");
require_once("packages/UserStore/UserStore_constants.php");
require_once("packages/NoteStore/NoteStore.php");
$username = ""; // Evernote username
$password = ""; // Evernote password
$consumerKey = ""; // Client API consumer key
$consumerSecret = ""; // Client API secret key
$evernoteHost = "sandbox.evernote.com";
$evernotePort = "443";
$evernoteScheme = "https";
echo "Starting thrift connection..." . NE;
$userStoreHttpClient = new THttpClient($evernoteHost, $evernotePort, "/edam/user", $evernoteScheme);
$userStoreProtocol = new TBinaryProtocol($userStoreHttpClient);
$userStore = new UserStoreClient($userStoreProtocol, $userStoreProtocol);
// "Clientname", 2nd/3rd defined in UserStore_constants.php
// Returns true or false
$versionOK = $userStore->checkVersion("EVERNOTE Client test",
$GLOBALS['UserStore_CONSTANTS']['EDAM_VERSION_MAJOR'],
$GLOBALS['UserStore_CONSTANTS']['EDAM_VERSION_MINOR']);
if (!$versionOK) {
echo "Version doesn't fit. Exiting.." . NE;
exit(1);
}
// Authenticate
try {
$authResult = $userStore->authenticate($username, $password, $consumerKey, $consumerSecret);
} catch(edam_error_EDAMUserException $eue) {
echo "Authentification failed: " . $eue . "\n\n";
var_dump($eue->errorCode); // https://www.evernote.com/about/developer/api/ref/Errors.html#Enum_EDAMErrorCode
exit(1);
}
echo "Authentification sucessful..." . NE;
$user = $authResult->user;
$authToken = $authResult->authenticationToken;
$noteStoreHttpClient = new THttpClient($evernoteHost, $evernotePort, "/edam/note/" . $user->shardId, $evernoteScheme);
$noteStoreProtocol = new TBinaryProtocol($noteStoreHttpClient);
$noteStore = new NoteStoreClient($noteStoreProtocol, $noteStoreProtocol);
$notebooks = $noteStore->listNotebooks($authToken);
print "Found " . count($notebooks) . " notebooks" . NE;
foreach ($notebooks as $notebook) {
echo "* " . $notebook->name . NE;
if ($notebook->defaultNotebook) {
$defaultNotebook = $notebook;
$defaultNotebookGUID = $notebook->guid;
}
}
if(isset($defaultNotebook)) {
echo "Dump content of default Notebook with GUID: " . $defaultNotebookGUID . NE;
echo "--------------------------------------------------------------------" . NE;
$noteFilter = new edam_notestore_NoteFilter();
$noteFilter->notebookGuid = $defaultNotebookGUID;
try {
$noteList = $noteStore->findNotes($authToken, $noteFilter, 0, 10);
} catch(edam_error_EDAMNotFoundException $enfe) {
echo "Not Found Exception: " . $enfe->identifier . " | " . $enfe->key;
} catch(edam_error_EDAMSystemException $ese) {
echo "System Exception: " . $ese->errorCode . " | " . $ese->parameter;
}
foreach($noteList->notes as $note) {
echo "Notes GUID: " . $note->guid . NE;
echo "Notes title: " . $note->title . NE;
echo "Notes content: " . strip_tags($noteStore->getNoteContent($authToken, $note->guid)) . NE;
echo "--------------------------------------------------------------------" . NE;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment