2016-11-08 80 views
0

我试图用PHP创建一个新的Business Notebook,但我没有运气。用PHP创建Evernote商业笔记本

我试过以下this documentation并使用Thrift module: NoteStore将代码调整为适合我的选项。

根据我对流量的理解,创建一个新笔记本,使用返回的笔记本获取其shareKey,shareID和businessId,使用该信息在商业笔记存储中创建链接的笔记本。

我第一次尝试使用非商业笔记存储创建新笔记本,但是返回的新笔记本没有包含shareKey或创建链接笔记本所需的任何其他信息。相反,我发现使用Business Note Store创建一个新笔记本返回了一个新的笔记本,其中一些是“sharedNotebooks”字段中的必需信息,但businessNotebook参数为null,并且sharedNotebooks中没有shareId。即使这款新笔记本电脑返回成功,它也无法在我的个人或企业账户中看到。

返回的笔记本电脑看起来像

{ 
    "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": "[email protected]", 
     "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": "[email protected]", 
     "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 
    } 
} 

到目前为止,我的代码流程如下//尝试为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"} 

回答

0

好的我已经能够使它工作。基本上,您的代码中存在太多错误:

  • username和shardId是用户的属性,而不是共享笔记本的属性。
  • 链接的笔记本必须在用户存储上创建,而不是在商业上创建。基本上,链接的笔记本只是您创建的“真实”共享商业笔记本的“链接”。它允许用户访问商业笔记本。

因此,这里的一些代码,为我工作:

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

希望帮助!

PS:说你好,克里斯我;)

+0

辉煌,谢谢!事后重新阅读https://dev.evernote。com/doc/articles/business.php,这正是它所要做的......对不起,我的时间花在你的时间!克里斯,我们都欣赏它! –

0

我刚刚有了一个快速浏览一下,所以我可能会错误,但description of the error code n°12是:“帐户数据服务碎片暂时关闭”

可能是一个临时错误。让我知道,如果情况并非如此,我会尝试花点时间检查这个问题。

+0

你好,感谢您的回复,我仍然但是我得到了相同的错误代码。我注意到我也试过改变最后一行''''newLinkedNotebook = $ bNoteStore-> createLinkedNotebook($ bAuthToken,$ newLinkedNotebook);'''使用$ bNoteStore $ noteStore以及非商业认证和它返回的错误是'''{“errorCode”:5,“parameter”:“LinkedNotebook.shardId”}'''这让我回到前面提到的问题,当我在商业票据存储中创建笔记本时, a sharekey and no shareId –

+0

好的,我今天会试着去看看。没有任何承诺,因为我现在有很多东西在我的盘子里。 –

相关问题