Evernote SDK:对共享笔记本进行身份验证

时间:2016-05-06 09:48:05

标签: android evernote

我尝试使用Evernote Android SDK访问共享笔记本。我从应用程序的服务器端通过REST api接收shareKey。我使用下面的代码:

AuthenticationResult result = EvernoteSession.getInstance()
                    .getEvernoteClientFactory()
                    .getNoteStoreClient()
                    .authenticateToSharedNotebook(shareKey);
            String token = result.getAuthenticationToken();
            String sharedNotebookStoreUrl = result.getNoteStoreUrl();
            TBinaryProtocol sharedNoteProtocol = new TBinaryProtocol(
                    new THttpClient(sharedNotebookStoreUrl));
            NoteStore.Client sharedNoteStore = new NoteStore.Client(sharedNoteProtocol);
            SharedNotebook sharedNotebook = sharedNoteStore.getSharedNotebookByAuth(token);

但是当我打电话时

AuthenticationResult result = EvernoteSession.getInstance()
                        .getEvernoteClientFactory()
                        .getNoteStoreClient()
                        .authenticateToSharedNotebook(shareKey);

它有一个异常

EDAMNotFoundException(identifier:SharedNotebook.id, key:39116)

我做错了什么?我如何接受共享和访问共享笔记本的内容?

2 个答案:

答案 0 :(得分:0)

您使用了错误的sharedNotebookStoreUrl

SharedNotebook是从帐户A到帐户B的Notebook N的份额记录。它存储在帐户A的noteStoreUrl(笔记本N)中。帐户B将具有指向SharedNotebook(而非笔记本)的相应LinkedNotebook记录。 LinkedNotebook将在帐号B上。

NoteStoreUrl for account A            NoteStoreUrl for account B
Notebook N                            LinkedNotebook L (points to S)
SharedNotebook S (points to N)

听起来像是你在帐户B中尝试访问笔记本N.你想要做的是从LinkedNotebook L中获取noteStoreUrl,然后使用它来调用authenticateToSharedNotebook。您可以通过调用listLinkedNotebooks来获取LinkedNotebooks。

答案 1 :(得分:0)

不确定这是否适用于您的确切方案,但您可以尝试以下方法在用户B的帐户中创建链接笔记本(我在稍微不同的情况下执行类似操作):

LinkedNotebook linkedNotebook = new LinkedNotebook();
linkedNotebook.SharedNotebookGlobalId = <the shareKey you got from the server>
linkedNotebook.ShareName = <the name of the Shared Notebook>
linkedNotebook.Username = <the username of user A; i.e. the owner of the Shared Notebook>
linkedNotebook.ShardId = <the shardId of the notebook in user A's account>
LinkedNotebook createdLinkedNotebook = noteStore.createLinkedNotebook(authenticationToken, linkedNotebook);