dongshi9407 2016-11-08 02:51
浏览 49
已采纳

用PHP创建Evernote商务笔记本

I'm trying to create a new Business Notebook over PHP but I'm having no luck.

I've tried following this documentation and adapting the code to what is available to me using the Thrift module: NoteStore.

From my understanding of how the flow is meant to be, it's; create a new notebook, using the returned notebook get its shareKey, shareID, and businessId, use that information to create a linked notebook in the business note store.

I first tried to creating a new notebook using the non business note store, however the new notebook returned did not contain a shareKey, or any other information needed for creating a linked notebook. Instead I found creating a new notebook using the business note store returned a new notebook with some of this the required information under the 'sharedNotebooks' feild however the businessNotebook parameter was null, and there was no shareId within sharedNotebooks. And even though this new notebook is returned successfull, it is not visable in my personal or business accounts.

The returned notebook looks like

{
    "guid": "d341cd12-9f98-XXX-XXX-XXX",
    "name": "Hello World",
    "updateSequenceNum": 35838,
    "defaultNotebook": false,
    "serviceCreated": 1478570056000,
    "serviceUpdated": 1478570056000,
    "publishing": null,
    "published": null,
    "stack": null,
    "sharedNotebookIds": [603053],
    "sharedNotebooks": [{
        "id": 603053,
        "userId": 40561553,
        "notebookGuid": "d341cd12-9f98-XXX-XXX-XXX",
        "email": "jack@businessEvernoteAccountEmail",
        "notebookModifiable": true,
        "requireLogin": null,
        "serviceCreated": 1478570056000,
        "serviceUpdated": 1478570056000,
        "shareKey": "933ad-xxx",
        "username": "xxx",
        "privilege": 5,
        "allowPreview": null,
        "recipientSettings": {
            "reminderNotifyEmail": null,
            "reminderNotifyInApp": null
        }
    }],
    "businessNotebook": null,
    "contact": {
        "id": 111858676,
        "username": "XXX",
        "email": "jack@personalEvernoteAccountEmail",
        "name": "Jack XXXX",
        "timezone": null,
        "privilege": null,
        "created": null,
        "updated": null,
        "deleted": null,
        "active": true,
        "shardId": null,
        "attributes": null,
        "accounting": null,
        "premiumInfo": null,
        "businessUserInfo": null
    },
    "restrictions": {
        "noReadNotes": null,
        "noCreateNotes": null,
        "noUpdateNotes": null,
        "noExpungeNotes": true,
        "noShareNotes": null,
        "noEmailNotes": true,
        "noSendMessageToRecipients": null,
        "noUpdateNotebook": null,
        "noExpungeNotebook": true,
        "noSetDefaultNotebook": true,
        "noSetNotebookStack": true,
        "noPublishToPublic": true,
        "noPublishToBusinessLibrary": null,
        "noCreateTags": null,
        "noUpdateTags": true,
        "noExpungeTags": true,
        "noSetParentTag": true,
        "noCreateSharedNotebooks": null,
        "updateWhichSharedNotebookRestrictions": null,
        "expungeWhichSharedNotebookRestrictions": null
    }
}

Thus far, my code flow is as follows //Try catches left out for sortness

//Check if business user
$ourUser = $this->userStore->getUser($authToken);
if(!isset($ourUser->accounting->businessId)){
    $returnObject->status = 400;
    $returnObject->message = 'Not a buisness user';
    return $returnObject;
}

// authenticateToBusiness and get business token
$bAuthResult = $this->userStore->authenticateToBusiness($authToken);
$bAuthToken = $bAuthResult->authenticationToken;

//Create client and set up business note store
$client = new \Evernote\AdvancedClient($authToken, false);
$bNoteStore = $client->getBusinessNoteStore();

//Create a new notebook in business note store- example result is json above
$newNotebook = new Notebook();
$newNotebook->name = $title;
$newNotebook = $bNoteStore->createNotebook($bAuthToken, $newNotebook);

//Look at new notebook and get information needed to create linked notebook
$sharedNotebooks = $newNotebook->sharedNotebooks[0];

$newLinkedNotebook = new LinkedNotebook();
$newLinkedNotebook->shareName = $title;
$newLinkedNotebook->shareKey = $sharedNotebooks->shareKey;
$newLinkedNotebook->username = $sharedNotebooks->username;
//$newLinkedNotebook->shardId = $sharedNotebooks->shardId; //isnt there

//This is where I think the trouble is happening ???
$newLinkedNotebook = $bNoteStore->createLinkedNotebook($bAuthToken, $newLinkedNotebook);

//Trying with business token throws 
//{"errorCode":3,"parameter":"authenticationToken"}
//Even though within Evernote itself, I can add notebooks to this business 


//Alternatively trying with the regular $authToken i receive 
//{"errorCode":12,"message":"s570","rateLimitDuration":null}
// error code 12 being SHARD_UNAVAILABLE

//and trying on the regular noteStore 
$newLinkedNotebook = $noteStore->createLinkedNotebook($authToken, $newLinkedNotebook);
//returns {"errorCode":5,"parameter":"LinkedNotebook.shardId"}
  • 写回答

2条回答 默认 最新

  • dongtao5055 2016-11-09 09:49
    关注

    OK I've been able to make it work. Basically, there are too mistakes in your code :

    • username and shardId are properties of the user, not of the shared notebook.
    • the linked notebook has to be created on the user store, not the business one. Basically the linked notebook is only a 'link' to the 'real' shared business notebook you created. It allows the user to access the business notebook.

    So here some code that work for me :

    $client = new \Evernote\AdvancedClient($authToken, false, null, null, false);
    
    $userStore = $client->getUserStore();
    $userNoteStore = $client->getNoteStore();
    
    $ourUser = $userStore->getUser($authToken);
    if(!isset($ourUser->accounting->businessId)){
        $returnObject = new \stdClass();
        $returnObject->status = 400;
        $returnObject->message = 'Not a buisness user';
        return $returnObject;
    }
    
    $bAuthResult = $userStore->authenticateToBusiness($authToken);
    $bAuthToken = $bAuthResult->authenticationToken;
    
    $bNoteStore = $client->getBusinessNoteStore();
    
    $title = 'My title';
    
    $newNotebook = new \EDAM\Types\Notebook();
    $newNotebook->name = $title;
    $newNotebook = $bNoteStore->createNotebook($bAuthToken, $newNotebook);
    
    $sharedNotebook = $newNotebook->sharedNotebooks[0];
    
    $newLinkedNotebook = new \EDAM\Types\LinkedNotebook();
    $newLinkedNotebook->shareName = $newNotebook->name;
    $newLinkedNotebook->shareKey = $sharedNotebook->shareKey;
    
    $newLinkedNotebook->username = $bAuthResult->user->username;
    $newLinkedNotebook->shardId = $bAuthResult->user->shardId;
    
    $newLinkedNotebook = $userNoteStore->createLinkedNotebook($authToken, $newLinkedNotebook);

    Hope that helps !

    PS: say hi to Chris for me ;)

    </div>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效