I am developing an iOS app that uses the Evernote API. Everything has been working fine, but then I started getting "code 403" to my requests.
Authentication to the service goes well: I am able log on and download all info I need (Notebooks, Notes, Note content, etc...). But when I try to get the thumbnails, I get 403.
My code for the request:
NSString *thumbnailPath = [NSString stringWithFormat:@"%@thm/note/%@?75", [[EvernoteSession sharedSession] webApiUrlPrefix], note.guid];
NSLog(@"THUMBNAILPATH %@", thumbnailPath);
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:[NSURL URLWithString:[[EvernoteSession sharedSession] webApiUrlPrefix]]];
[httpClient clearAuthorizationHeader];
[httpClient setAuthorizationHeaderWithToken:[[EvernoteSession sharedSession] authenticationToken]];
[httpClient postPath:thumbnailPath parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
note.thumbnail = responseObject;
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"REQUEST: %@", thumbnailPath);
NSLog(@"Error: %@", error.localizedDescription);
}];
If I copy what the "REQUEST:" log result, it is a well-formatted link that gives me the thumbnail in my browser. But the second log gives me: "Error: Expected status code in (200-299), got 403".
I am out of ideas. Can anyone help?
You are not passing in the auth token correctly. This is how you would request a thumbnail for a note on iOS :
- (void)getThumbnailWithNoteGuid:(NSString*)noteGUID {
EvernoteSession* session = [EvernoteSession sharedSession];
NSString* fullTumbnailURL = [NSString stringWithFormat:@"%@thm/note/%@",[[EvernoteSession sharedSession]webApiUrlPrefix],noteGUID];
NSURL *url = [NSURL URLWithString:fullTumbnailURL];
NSMutableURLRequest* urlReq = [NSMutableURLRequest requestWithURL:url];
[urlReq setHTTPMethod:@"POST"];
[urlReq setHTTPBody:[[NSString stringWithFormat:@"auth=%@",[session.authenticationToken URLEncodedString]] dataUsingEncoding:NSUTF8StringEncoding]];
NSLog(@"full URL %@",fullTumbnailURL);
[NSURLConnection sendAsynchronousRequest:urlReq queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *urlREsp, NSData *respData, NSError *error) {
if(error == nil) {
NSLog(@"Thumbail data : %@",respData);
};
}];
}
403 - means forbidden. I haven't got expirience working with evernote but in based on other SDK's you're doing something wrong with request either you should go to evernote developers page. log in to your's account and look for some triggers. may be there some triggers which you should turn on to use this features
You should:
Set a breakpoint in -[AFHTTPClient postPath: parameters: success: failure:]
. In the debugger, type po request
to see the full URL that AFNetworking is hitting. Make sure that's what you want.
In your failure block, you're only looking at the error
object, created by AFNetworking to summarize the issue. However, the Evernote API could be providing additional info in the response body, which you can look at with NSLog(@"Response Body: %@", [operation responseString])
.
Ultimately, your AFNetworking code is fine - this looks like an Evernote API issue. You're making the request wrong, your token is expired, or there's a bug on their end.
note.thumbnail = responseObject;
. responseObject
could be anything; make sure it's what you expect before you call your setter.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.