我正在开发一个绘图工具项目的应用程序,我们需要将图像从evernote帐户导入我的应用程序。
我使用下面的代码来获取备注列表。但我无法解码" data.bodyHash" NSData和图像变为零。您可以在下面的代码中看到。
EvernoteSession *session = [EvernoteSession sharedSession];
EDAMNoteFilter* filter = [[EDAMNoteFilter alloc] initWithOrder:0 ascending:NO words:nil notebookGuid:nil tagGuids:nil timeZone:nil inactive:NO emphasized:nil];
[[EvernoteNoteStore noteStore] findNotesWithFilter:filter offset:0 maxNotes:100 success:^(EDAMNoteList *list) {
for (EDAMNote *note in list.notes) {
NSLog(@"Notes : %@",note.title);
NSMutableArray *resources = note.resources;
if (resources!=nil) {
EDAMResource* resource = [resources objectAtIndex:0];
EDAMData *data = resource.data;
UIImage *image = [[UIImage alloc]initWithData:data.bodyHash];
/// Image is nil
}
}
}
由于
答案 0 :(得分:4)
是的,这是可能的。您应该采取一些步骤来达到预期的效果。
1)确保您的Evernote应用程序具有对用户的Evernote帐户的完全访问权限,以便能够阅读现有笔记(您可以在https://dev.evernote.com上请求Evernote API密钥时进行设置)
2)验证
[self.session authenticateWithViewController:self
preferRegistration:NO
completion:^(NSError* authenticateError) {
...
}];
3)找到所有笔记
[self.session findNotesWithSearch:nil
inNotebook:nil
orScope:ENSessionSearchScopeAll
sortOrder:ENSessionSortOrderNormal
maxResults:255
completion:^(NSArray* findNotesResults,
NSError* findNotesError) {
...
}];
4)下载每个笔记
for (ENSessionFindNotesResult* result in findNotesResults) {
[self.session downloadNote:result.noteRef
progress:NULL
completion:^(ENNote* note,
NSError* downloadNoteError) {
...
}];
}
5)获取所有图像
for (ENResource* resource in note.resources) {
if ([resource.mimeType hasPrefix:@"image"]) {
UIImage* image = [[UIImage alloc] initWithData:resource.data];
...
}
}
您可以查看sample project here 如果您设置了使用者密钥和密钥,则在身份验证之后您将看到类似的控制台输出:
2014-08-19 22:54:18.782 EvernoteTest[71234:60b] finding all notes..
2014-08-19 22:54:20.356 EvernoteTest[71234:60b] processing find notes results..
2014-08-19 22:54:21.294 EvernoteTest[71234:60b] getting images from note 'Just Image'
2014-08-19 22:54:21.294 EvernoteTest[71234:60b] >> image with size {600, 400}
2014-08-19 22:54:21.295 EvernoteTest[71234:60b]
2014-08-19 22:54:21.720 EvernoteTest[71234:60b] getting images from note 'Getting Started'
2014-08-19 22:54:21.721 EvernoteTest[71234:60b] >> image with size {27, 27}
2014-08-19 22:54:21.721 EvernoteTest[71234:60b] >> image with size {215, 54}
2014-08-19 22:54:21.722 EvernoteTest[71234:60b] >> image with size {300, 300}
2014-08-19 22:54:21.722 EvernoteTest[71234:60b] >> image with size {27, 27}
2014-08-19 22:54:21.723 EvernoteTest[71234:60b] >> image with size {27, 27}
2014-08-19 22:54:21.723 EvernoteTest[71234:60b] >> image with size {27, 27}
2014-08-19 22:54:21.724 EvernoteTest[71234:60b] >> image with size {27, 27}
2014-08-19 22:54:21.724 EvernoteTest[71234:60b] >> image with size {27, 27}
2014-08-19 22:54:21.725 EvernoteTest[71234:60b] >> image with size {27, 27}
2014-08-19 22:54:21.725 EvernoteTest[71234:60b]
2014-08-19 22:54:22.179 EvernoteTest[71234:60b] getting images from note 'Another Image'
2014-08-19 22:54:22.180 EvernoteTest[71234:60b] >> image with size {685, 514}
2014-08-19 22:54:22.180 EvernoteTest[71234:60b]
希望这有帮助