Created
July 14, 2017 15:57
-
-
Save freakinhuge/7dc96406e9aaeb3930b2cfc67248c7d2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$token = 'YOUR TOKEN HERE'; | |
$client = new \Evernote\Client($token, false); | |
$advancedClient = $client->getAdvancedClient(); | |
$notebookGuid = 'YOUR SHARED NOTEBOOK GUID'; | |
$noteStore = $advancedClient->getNoteStore(); | |
$linkedNotebooks = $noteStore->listLinkedNotebooks($token); | |
foreach ($linkedNotebooks as $linkedNotebook) { | |
if ($linkedNotebook->guid == $notebookGuid) { | |
$parts = parse_url($linkedNotebook->noteStoreUrl); | |
if (!isset($parts['port'])) { | |
if ($parts['scheme'] === 'https') { | |
$parts['port'] = 443; | |
} else { | |
$parts['port'] = 80; | |
} | |
} | |
$sharedNoteStoreHttpClient = | |
new \Thrift\Transport\THttpClient($parts['host'], $parts['port'], $parts['path'], $parts['scheme']); | |
$sharedNoteStoreProtocol = new \Thrift\Protocol\TBinaryProtocol($sharedNoteStoreHttpClient); | |
$sharedNoteStore = new \EDAM\NoteStore\NoteStoreClient($sharedNoteStoreProtocol, $sharedNoteStoreProtocol); | |
$sharedAuthResult = | |
$sharedNoteStore->authenticateToSharedNotebook($linkedNotebook->shareKey, $token); | |
$sharedAuthToken = $sharedAuthResult->authenticationToken; | |
$sharedNotebook = $sharedNoteStore->getSharedNotebookByAuth($sharedAuthToken); | |
$filter = new \EDAM\NoteStore\NoteFilter(); | |
$filter->notebookGuid = $sharedNotebook->notebookGuid; // only from the shared notebook | |
$filter->order = 2; // order by recently created first | |
$noteList = $sharedNoteStore->findNotes($sharedAuthToken, $filter, 0, 10); // only return the last 10 notes | |
// create note | |
$note = new \EDAM\Types\Note(); | |
$note->title = 'YOUR TITLE'; | |
$note->notebookGuid = $sharedNotebook->notebookGuid; | |
$enmlContent = <<<ENML | |
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd"> | |
<en-note>YOUR CONTENT</en-note> | |
ENML | |
; | |
$note->content = $enmlContent; | |
$uploadedNote = $sharedNoteStore->createNote($sharedAuthToken,$note); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment