The operation couldn’t be completed. (com.google.HTTPStatus error 401.)
I know erros 401 stands unauthorized access, but I've set authorizer to GTMHTTPFetcher object. Please find the below code.
- (GDataServiceGoogleContact *)contactService {
static GDataServiceGoogleContact* service = nil;
if (!service) {
service = [[GDataServiceGoogleContact alloc] init];
[service setShouldCacheResponseData:YES];
[service setServiceShouldFollowNextLinks:YES];
MyAppDelegate *appDelegate = (MyAppDelegate *) [[UIApplication sharedApplication] delegate];
[service setAuthorizer:appDelegate.auth];
}
return service;
}
- (void) loadImageInBackGround:(NSIndexPath*) indexPath {
GDataEntryContact *contact = [[self contacts] objectAtIndex:indexPath.row];
GDataLink *photoLink = [contact photoLink];
// get an NSURLRequest object with an auth token
NSURL *imageURL = [photoLink URL];
GDataServiceGoogleContact *service = [self contactService];
NSMutableURLRequest *request = [service requestForURL:imageURL ETag:nil httpMethod:nil];
[request setValue:@"image/*" forHTTPHeaderField:@"Accept"];
GTMHTTPFetcher *fetcher = [GTMHTTPFetcher fetcherWithRequest:request];
[fetcher setAuthorizer:[service authorizer]];
[GTMHTTPFetcher setLoggingEnabled:YES];
[fetcher beginFetchWithCompletionHandler:^(NSData* data, NSError* error) {
if (error) {
NSLog(@"error => %@", [error localizedDescription]);
} else { NSLog (@"You got the image"); }];
}}I enable the logging on Fetcher and the result is;
Request: GET https://www.google.com/m8/feeds/photos/media/example%40gmail.com/6338707b0cc6a57d Request headers: Accept: image/* Authorization: Bearer _snip_ GData-Version: 3.0 Response: status 401 Response headers: Cache-Control: private, max-age=0 Content-Type: text/html; charset=utf-8 Date: Thu, 29 Nov 2012 04:32:33 GMT Expires: Thu, 29 Nov 2012 04:32:33 GMT Server: GSE Transfer-Encoding: Identity X-Content-Type-Options: nosniff X-Frame-Options: SAMEORIGIN X-XSS-Protection: 1; mode=blockAny help appreciated.
NSString* scope = [NSString stringWithFormat:@"%@ %@", kGTLAuthScopePlusMe, [GDataServiceGoogleContact authorizationScope]];
GTMOAuth2ViewControllerTouch *viewController = [[GTMOAuth2ViewControllerTouch alloc] initWithScope:scope
clientID:[MyAppDelegate apiClientID]
clientSecret:nil
keychainItemName:kKeychainItemName
delegate:self
finishedSelector:@selector(viewController:finishedWithAuth:error:)];
I was able to fetch contact entries and its properties except images. I checked with api console and found that Google+ API is enabled for my app. Am missing anything else?
Thanks.