无法在PHP中使用Evernote API实例化Note对象

时间:2013-05-22 15:27:14

标签: php api evernote

我正在尝试开发一个脚本(使用PHP示例应用程序作为基础),它将根据GET值向Evernote发布注释。

当我将此插入到functions.php的listNotebooks()

的末尾时
$note_obj = new Note(array(
                'contents' => $note_contents,
                'title' => $title
                ));

它会抛出500错误。 (在我的代码中,$ title& $ note_contents是先前定义的。我花了很多时间试图找到PHP API的正确文档,但它似乎不存在。非常感谢有关此主题的任何信息

更新:我没有意识到API使用的是PHP命名空间:这解决了这个问题:

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

我添加注释的代码仍然不起作用,但是一旦我弄明白,我就会在这里发布。

1 个答案:

答案 0 :(得分:2)

需要导入这些类:

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

这将定义我们的新笔记:

       $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);

此功能将添加一个新注释:

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;
}
}