Question

I am trying to develop a script (using the PHP example app as a basis) that will post a note to Evernote based on GET values.

When I insert this to the end of functions.php's listNotebooks()

$note_obj = new Note(array(
                'contents' => $note_contents,
                'title' => $title
                ));

It throws a 500 error. (In my code, $title & $note_contents are defined earlier. I have spent a lot of time trying to find proper documentation for the PHP API but it just seems non-existent. Any information on this topic would be greatly appreciated

Update: I did not realize the API was using PHP Namespaces: This fixed the issue:

//import Note class
use EDAM\Types\Note;
use EDAM\Types\NoteAttributes;
use EDAM\NoteStore\NoteStoreClient;

My code to add a note still does not work but I'll post it here once I figure it out.

Was it helpful?

Solution

These classes need to be imported:

//import Note class
use EDAM\Types\Note;
use EDAM\Types\NoteAttributes;
use EDAM\NoteStore\NoteStoreClient;

This will define our new note:

       $noteAttr = new NoteAttributes();
                $noteAttr->sourceURL = "http://www.example.com";
                $note = new Note();
                $note->guid = null;
                $note->title = "My Title";
                $note->content = '<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml.dtd"><en-note>My Content</en-note>';
                $note->contentHash = null;
                $note->contentLength = null;
                $note->created = time()*1000;
                $note->updated = time()*1000;
                $note->deleted = null;
                $note->active = null;
                $note->updateSequenceNum = null;
                $note->notebookGuid = null;
                $note->tagGuids = null;
                $note->resources = null;
                $note->attributes = $noteAttr;
                $note->tagNames = null;
                addNote($note);

This function will add a new note:

function addNote($newnote) {
    global $noteRet;
    if (empty($noteRet)) {
        define("noteStoreHost", "sandbox.evernote.com");
define("noteStorePort", "80");
define("noteStoreProto", "https");
define("noteStoreUrl", "edam/note/");
            $noteStoreTrans = new THttpClient(noteStoreHost, noteStorePort, noteStoreUrl . $_SESSION['shardId'], noteStoreProto);
            $noteStoreProt = new TBinaryProtocol($noteStoreTrans);
            $noteStore = new NoteStoreClient($noteStoreProt, $noteStoreProt);
            $noteRet = $noteStore->createNote($_SESSION['accessToken'], $newnote);

    return $noteRet;
}
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top