在 PHP 中创建 Evernote 企业笔记本
Creating Evernote Business Notebooks in PHP
我正在尝试在 PHP 上创建一个新的 Business Notebook
,但我没有运气。
我试过关注 this documentation and adapting the code to what is available to me using the Thrift module: NoteStore。
根据我对流程的理解,它是;创建一个新笔记本,使用返回的笔记本获取其 shareKey、shareID 和 businessId,使用该信息在商业笔记商店中创建链接笔记本。
我首先尝试使用非商业笔记商店创建一个新笔记本,但是返回的新笔记本不包含 shareKey 或创建链接笔记本所需的任何其他信息。相反,我发现使用商业笔记商店创建一个新笔记本会返回一个新笔记本,其中包含 'sharedNotebooks' 字段下的一些必需信息,但是 businessNotebook 参数为空,并且 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": "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
}
}
到目前为止,我的代码流程如下 //尝试为了排序而遗漏的捕获
//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"}
我只是快速浏览了一下,所以我可能错了,但是 description of the error code n° 12 是:"Service shard with account data is temporarily down"
可能是暂时性错误。让我知道,如果不是这种情况,我会尝试花一些时间来检查这个问题。
好的,我已经成功了。基本上,你的代码错误太多了:
- username 和 shardId 是用户的属性,而不是共享笔记本的属性。
- 必须在用户存储而不是企业存储上创建链接的笔记本。基本上,链接笔记本只是您创建的 'real' 共享商务笔记本的 'link'。它允许用户访问商务笔记本。
这里有一些适合我的代码:
$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:代我向克里斯问好 ;)
我正在尝试在 PHP 上创建一个新的 Business Notebook
,但我没有运气。
我试过关注 this documentation and adapting the code to what is available to me using the Thrift module: NoteStore。
根据我对流程的理解,它是;创建一个新笔记本,使用返回的笔记本获取其 shareKey、shareID 和 businessId,使用该信息在商业笔记商店中创建链接笔记本。
我首先尝试使用非商业笔记商店创建一个新笔记本,但是返回的新笔记本不包含 shareKey 或创建链接笔记本所需的任何其他信息。相反,我发现使用商业笔记商店创建一个新笔记本会返回一个新笔记本,其中包含 'sharedNotebooks' 字段下的一些必需信息,但是 businessNotebook 参数为空,并且 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": "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
}
}
到目前为止,我的代码流程如下 //尝试为了排序而遗漏的捕获
//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"}
我只是快速浏览了一下,所以我可能错了,但是 description of the error code n° 12 是:"Service shard with account data is temporarily down"
可能是暂时性错误。让我知道,如果不是这种情况,我会尝试花一些时间来检查这个问题。
好的,我已经成功了。基本上,你的代码错误太多了:
- username 和 shardId 是用户的属性,而不是共享笔记本的属性。
- 必须在用户存储而不是企业存储上创建链接的笔记本。基本上,链接笔记本只是您创建的 'real' 共享商务笔记本的 'link'。它允许用户访问商务笔记本。
这里有一些适合我的代码:
$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:代我向克里斯问好 ;)