queryForColorsGet does not work

128 views
Skip to first unread message

Dice-K

unread,
Nov 28, 2011, 12:26:47 AM11/28/11
to Google APIs Client Library for Objective-C
GTLQueryCalendar *query = [GTLQueryCalendar queryForColorsGet];
[service executeQuery:query completionHandler:^(GTLServiceTicket
*ticket, id object, NSError *error) {
if (error == nil) {
NSLog(@"%@", object);
}
else {
NSLog(@"%@", error);
}
}];


It cause Domain=com.google.GTLJSONRPCErrorDomain Code=403 "The
operation couldn’t be completed. (Daily Limit Exceeded. Please sign
up)"

However, the code below works. Why?


NSURL *url = [NSURL URLWithString:@"https://www.googleapis.com/
calendar/v3/colors?key=MYKEY"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
GTMHTTPFetcherService *fetcherService = [service fetcherService];
GTMHTTPFetcher *fetcher = [fetcherService
fetcherWithRequest:request];
[fetcher beginFetchWithCompletionHandler:^(NSData *data, NSError
*error) {
if (error == nil) {
NSString *str = [[NSString alloc] initWithData:data
encoding:NSUTF8StringEncoding];
NSLog(@"%@", str);
[str release];
}
}];

Greg Robbins

unread,
Nov 28, 2011, 12:46:46 AM11/28/11
to google-api-obj...@googlegroups.com
The error "Daily Limit Exceeded" could indicate that the request is not being authenticated properly. Does the service have the correct authorizer object for the signed-in user?

Dice-K

unread,
Nov 28, 2011, 1:23:02 AM11/28/11
to Google APIs Client Library for Objective-C
I maybe have valid auth key, because second code below return JSON
object of CalendarColors.
I think that if the service has no authorizer object, second code also
fails. Is it right?

Greg Robbins

unread,
Nov 28, 2011, 1:30:05 AM11/28/11
to google-api-obj...@googlegroups.com
GTLQueryCalendar does not use the REST URL for making requests. 

It is not clear from the source code what request headers are in the server requests in either case.

Try turning on http logging and comparing the requests and responses, including headers, that are shown in the logs.


Dice-K

unread,
Nov 28, 2011, 2:30:08 AM11/28/11
to Google APIs Client Library for Objective-C
Greg,

Thank you for your advice. My service has auth object but fails.
I can get calendars.list and events.list with same service but colors.
Do I have to add some header properties else?

Dice-K

calendar.colors.get

2011-11-28 07:19:46 +0000
Request: POST https://www.googleapis.com/rpc?prettyPrint=false
Request headers:
Accept: application/json-rpc
Authorization: Bearer _snip_
Cache-Control: no-cache
Content-Type: application/json-rpc; charset=utf-8
User-Agent: jp.co.cybernet.CSC.GTLCalendar/1.0 google-api-objc-
client/2.0 iPhone_Simulator/5.0 (gzip)

Request body: (100 bytes)
{
"method" : "calendar.colors.get",
"id" : "gtl_3",
"jsonrpc" : "2.0",
"apiVersion" : "v3"
}

Response: status 200
Response headers:
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Content-Encoding: gzip
Content-Type: application/json; charset=UTF-8
Date: Mon, 28 Nov 2011 07:19:46 GMT
Expires: Fri, 01 Jan 1990 00:00:00 GMT
Pragma: no-cache
Server: GSE
Transfer-Encoding: Identity
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block

Response body: (256 bytes)
{
"id" : "gtl_3",
"error" : {
"message" : "Daily Limit Exceeded. Please sign up",
"code" : 403,
"data" : [
{
"domain" : "usageLimits",
"reason" : "dailyLimitExceededUnreg",
"extendedHelp" : "https:\/\/code.google.com\/apis\/console",
"message" : "Daily Limit Exceeded. Please sign up"
}
]
}
}

> http://code.google.com/p/google-api-objectivec-client/wiki/Introducti...

Greg Robbins

unread,
Nov 28, 2011, 2:37:59 AM11/28/11
to google-api-obj...@googlegroups.com
Check the status and quota settings for the specific project's service entry at http://code.google.com/apis/console/

David Phillip Oster

unread,
Jan 3, 2012, 8:46:46 PM1/3/12
to Google APIs Client Library for Objective-C
I've hit this same issue, and you, Dice-K, do appear to have solved
it.

You have to use https://code.google.com/apis/console to get an APIKey
for your project. Then, at runtime, you assign to the APIKey property
of the Calendar Service. Once you do that,

GTLServiceCalendar *service = [self serviceCalendar];
[service setAPIKey:kMyAPIKey];
NSURL *url = [NSURL URLWithString:@"https://www.googleapis.com/
calendar/v3/colors"];
[self addTicket:[service fetchObjectWithURL:url
objectClass:[GTLCalendarColors
class]
delegate:self

didFinishSelector:@selector(ticket:fetchCalendarColors:error:)]];

will call the callback with the calendar colors. This is kind-of
implied by the documentation that says you use the APIKey when making
requests that don't involve user data, and by the error returned by
the server, which asks you to sign in.

But, it is still confusing that some requests need OAuth signing,
while others require an APIKey.

Once you've got the colors, you can turn a color index into an RGB
triplet (as a NSString) like this:
[[[colors calendar] additionalPropertyForName:@"18"] foreground]

You can get a list of the legal index names using [[colors calendar]
additionalJSONKeys]

That is, a GTLCalendarColors has a set of string-valued property keys
that represent integers, where the value is a
GTLCalendarColorDefinition, which has two properties, foreground, and
background, each of which is a 6 character hex NSString, with a
leading '#'. that represents an R.G.B. triplet.

The sane thing to do is: write a category on GTLCalendarColors that
takes an integer and either kForeground or kBackground, and returns an
NSColor (or UIColor on iOS) else nil.




On Nov 27 2011, 11:30 pm, Dice-K <kgt.dnisi...@gmail.com> wrote:
> Greg,
>
> Thank you for your advice. My service has auth object but fails.
> I can get calendars.list and events.list with same service but colors.
> Do I have to add some header properties else?
>
> Dice-K
>
> calendar.colors.get
>
> 2011-11-28 07:19:46 +0000
> Request: POSThttps://www.googleapis.com/rpc?prettyPrint=false

David Phillip Oster

unread,
Jan 5, 2012, 5:24:48 PM1/5/12
to google-api-obj...@googlegroups.com
Rather than using fetchObjectWithURL: , this is better and also works (now that I know about the APIKey):

  GTLServiceCalendar *service = [self serviceCalendar];
  GTLQueryCalendar *query = [GTLQueryCalendar queryForColorsGet]; // <-- this
  [self addTicket:[service executeQuery:query
Reply all
Reply to author
Forward
0 new messages