Evernote SDK: Authenticate to shared notebook

半世苍凉 提交于 2019-12-11 13:56:22

问题


I'm trying to gain access to shared notebook using Evernote Android SDK. I'm receiving shareKey via REST api from server side of the applicaiton. I'm using the code below:

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

But when I call

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

it trows an exception

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

What I am doing wrong? How I can accept sharing and access to shared notebook's content?


回答1:


You're using the wrong sharedNotebookStoreUrl.

A SharedNotebook is the record of a share of a Notebook N from account A to account B. It is stored in the noteStoreUrl of account A (notebook N). Account B will have a corresponding LinkedNotebook record that points to the SharedNotebook (not the notebook). The LinkedNotebook will be on account B.

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

Sounds like you're in account B and trying to access the Notebook N. What you want to do is fetch the noteStoreUrl from the LinkedNotebook L and then use that to call authenticateToSharedNotebook. You can fetch the LinkedNotebooks by calling listLinkedNotebooks.




回答2:


Not sure if this will work in your exact scenario, but you can try the following to create the Linked Notebook in User B's account (I do something similar to this in a slightly different scenario):

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


来源:https://stackoverflow.com/questions/37069259/evernote-sdk-authenticate-to-shared-notebook

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!