2016-11-08 81 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

好的,我今天會試着去看看。沒有任何承諾,因爲我現在有很多東西在我的盤子裏。 –

相關問題