Reputation: 51
I am developing an app which is drawing tool project and we need to import image from evernote account into my app.
I am using below code to get note list. But i am not able to decode "data.bodyHash" NSData and image become nil. You can see in below code.
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
}
}
}
Thanks
Upvotes: 2
Views: 166
Reputation: 3252
Yes, it's possible. There are steps you should take to achieve the desired result.
1) Ensure that your Evernote Application has full access to user's Evernote account to able to read existing notes (you can set this up when requesting Evernote API Key on https://dev.evernote.com )
2) Authenticate
[self.session authenticateWithViewController:self
preferRegistration:NO
completion:^(NSError* authenticateError) {
...
}];
3) Find all notes
[self.session findNotesWithSearch:nil
inNotebook:nil
orScope:ENSessionSearchScopeAll
sortOrder:ENSessionSortOrderNormal
maxResults:255
completion:^(NSArray* findNotesResults,
NSError* findNotesError) {
...
}];
4) Download each note
for (ENSessionFindNotesResult* result in findNotesResults) {
[self.session downloadNote:result.noteRef
progress:NULL
completion:^(ENNote* note,
NSError* downloadNoteError) {
...
}];
}
5) Get all images
for (ENResource* resource in note.resources) {
if ([resource.mimeType hasPrefix:@"image"]) {
UIImage* image = [[UIImage alloc] initWithData:resource.data];
...
}
}
You can check sample project here.
If you set consumer key and secret, after authentication you'll see similar console output:
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]
Hope this helps
Upvotes: 4