i'm constantly amazed at just how complicated google can make their API libraries
10 months, 1 week ago.
9 comments so far
Contacts API, what is the most likely thing you want to do with this? I would say fetch the list of contacts in "My Contacts"... to do this you need to instantiate a ContactsService instance, override its auth token logic so that it will be able to find your auth token (it has some trouble with its own "scope" ideas), make a call to get a list of groups which returns an instance of GroupsFeed which has something like 20 inherited properties that have nothing to do with groups and do nothing on their own, and after digging through a series of superclasses amongst a couple projects you get to a class that also sets those same 20 inherited properties and STILL does nothing, whose superclass does the same plus a couple more namespace declarations, whose superclass does the same, whose superclass eventually defines a "ToString" method. The mixed in class provides an "interface" for finding out what the Atom edit / next / prev links are.
At this point you might be pretty confused as to what these classes all even do, since they actually do nothing. Turns out there is some other function, "CreateClassFromXMLString" that basically fills these up like the big ugly data structures that they are. Excuse me, don't we already have dictionaries and lists in python? I suppose java devs can write java in any language.
Anyway, once you've figured out how to iterate over the lists of groups (hint: try looking for an "entry" attribute) and figured out which one is the group that has the special flag for "My Contacts" you can make an additional call to get contacts filtered by that group and eventually iterate over its overzealously nested structure to get at what you are probably looking for.
As much as I like Atom and ReST (all hail Roy Fielding) I sometimes find it gets in the way of what you're trying to do. Usually this bites you when you want to do something with large amounts of data but all your early testing has used small datasets. And for maximum fun you now have to quickly find a new way to do something that you've already told people you've solved.
@adewale: Yeah, it's all autogenerated, and very obviously so, to almost no useful purpose. Most of the GData libraries are like this and don't provide any additional utility to the API, almost every one needs a higher level interface.
Sounds like you need DOM functions .. xpath sounds like what you need .. which should be part of an XML parsing library .. which means .. why on EARTH are they turning XML into an auto generated data structure? That's DUMB unless there is a very clear wrapper library around retrieving the data.
When I deal with it I just use the gdata libraries for signing and ask it to return json and then just process it all on my own, much less complicated than the "expected" way
@termie I have a nasty suspicion that's how all the real work with those APIs gets done. People send http requests and then manually process the resulting XML.
Eventually someone else comes along and builds an idiomatic implementation of the libraries for their particular language and their community standardises on that.
9 comments so far
Contacts API, what is the most likely thing you want to do with this? I would say fetch the list of contacts in "My Contacts"... to do this you need to instantiate a ContactsService instance, override its auth token logic so that it will be able to find your auth token (it has some trouble with its own "scope" ideas), make a call to get a list of groups which returns an instance of GroupsFeed which has something like 20 inherited properties that have nothing to do with groups and do nothing on their own, and after digging through a series of superclasses amongst a couple projects you get to a class that also sets those same 20 inherited properties and STILL does nothing, whose superclass does the same plus a couple more namespace declarations, whose superclass does the same, whose superclass eventually defines a "ToString" method. The mixed in class provides an "interface" for finding out what the Atom edit / next / prev links are.
At this point you might be pretty confused as to what these classes all even do, since they actually do nothing. Turns out there is some other function, "CreateClassFromXMLString" that basically fills these up like the big ugly data structures that they are. Excuse me, don't we already have dictionaries and lists in python? I suppose java devs can write java in any language.
Anyway, once you've figured out how to iterate over the lists of groups (hint: try looking for an "entry" attribute) and figured out which one is the group that has the special flag for "My Contacts" you can make an additional call to get contacts filtered by that group and eventually iterate over its overzealously nested structure to get at what you are probably looking for.
10 months, 1 week ago by termie
@termie: I'm amazed that you can explain complicated structures so good as you do.
10 months, 1 week ago by alexz
From this: http://code.google.com/intl/en/apis/contacts/docs/1.0/developersguidepython.html#retrievingwithquery and this:http://code.google.com/intl/en/apis/contacts/docs/1.0/developersguideprotocol.html it looks a lot like someone is auto-generating the code from the GData/Atom xml structures. Or at least making library users deal with the structure of Atom rather than just giving you the data you want.
As much as I like Atom and ReST (all hail Roy Fielding) I sometimes find it gets in the way of what you're trying to do. Usually this bites you when you want to do something with large amounts of data but all your early testing has used small datasets. And for maximum fun you now have to quickly find a new way to do something that you've already told people you've solved.
10 months, 1 week ago by adewale
@adewale: Yeah, it's all autogenerated, and very obviously so, to almost no useful purpose. Most of the GData libraries are like this and don't provide any additional utility to the API, almost every one needs a higher level interface.
10 months, 1 week ago by termie
s/higher level/user oriented/
10 months, 1 week ago by termie
This echoes my experience with the YouTube API perfectly. Trying to introspect the objects returned was a nightmare.
10 months, 1 week ago by UnConeD
Sounds like you need DOM functions .. xpath sounds like what you need .. which should be part of an XML parsing library .. which means .. why on EARTH are they turning XML into an auto generated data structure? That's DUMB unless there is a very clear wrapper library around retrieving the data.
10 months, 1 week ago by RickMeasham
When I deal with it I just use the gdata libraries for signing and ask it to return json and then just process it all on my own, much less complicated than the "expected" way
10 months, 1 week ago by termie
@termie I have a nasty suspicion that's how all the real work with those APIs gets done. People send http requests and then manually process the resulting XML.
Eventually someone else comes along and builds an idiomatic implementation of the libraries for their particular language and their community standardises on that.
10 months, 1 week ago by adewale