Search code examples
iosobjective-cgdatagmail-api

GTMHTTPFetcher Gmail Contact Photo Returns status 503 (sometimes)


I am using gdata to fetch app user's gmail contacts photo, exactly the following code. but sometimes the fetch work, sometimes it does not and gives me the following error: (I was suspecting too many tokens are given to google server? though I am not quite familiar with this concept yet. But I do need to fetch all of user`s contacts photo, is there a way to get around with it??)

Thank you in advance,

imageFetcher:GTMHTTPFetcher 0x145ea3300 (https://www.google.com/m8/feeds/photos/media/XXXXX%40gmail.com/XXXXX) failedWithError:Error Domain=com.google.HTTPStatus Code=503 "The operation couldn’t be completed. (com.google.HTTPStatus error 503.)"

if ([[[contact photoLink] ETag] length] ) {
                // imageData = [NSData dataWithContentsOfURL:photoURL];
                // requestForURL:ETag:httpMethod: sets the user agent header of the
                // request and, when using ClientLogin, adds the authorization header
                // get an NSURLRequest object with an auth token

                self.flyingtoken ++;
                NSURL *imageURL = [[contact photoLink] URL];
                GDataServiceGoogleContact *service = [self contactService];

                // requestForURL:ETag:httpMethod: sets the user agent header of the
                // request and, when using ClientLogin, adds the authorization header
                NSMutableURLRequest *request = [service requestForURL:imageURL
                                                                 ETag:nil
                                                           httpMethod:nil];

                [request setValue:@"image/*" forHTTPHeaderField:@"Accept"];

                GTMHTTPFetcher *fetcher = [GTMHTTPFetcher fetcherWithRequest:request];
                [fetcher setAuthorizer:[service authorizer]];
                [fetcher beginFetchWithDelegate:self
                              didFinishSelector:@selector(imageFetcher:finishedWithData:error:)];

            }

Solution

  • 503 error is generally returned by google server indicating your quota has exceeded. Try implementing exponential back off developers.google.com/api-client-library/java/…