【问题标题】:Cannot instantiate a Note object using Evernote API in PHP无法在 PHP 中使用 Evernote API 实例化笔记对象
【发布时间】:2013-05-17 17:46:49
【问题描述】:

我正在尝试开发一个脚本(使用 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;

我添加注释的代码仍然无法正常工作,但我会在弄清楚后将其发布在这里。

【问题讨论】:

  • 如果它抛出 500 错误,那是服务器错误,这意味着问题可能不是您的代码...我建议您查看支持论坛(如果有的话)。

标签: php api evernote


【解决方案1】:

需要导入这些类:

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

【讨论】:

    猜你喜欢
    • 2011-09-21
    • 1970-01-01
    • 1970-01-01
    • 2016-01-18
    • 1970-01-01
    • 2017-04-13
    • 2017-03-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多