I am pretty new to android; I would like to access google books from my android app. Can anyone provide any pointers, sample code开发者_JS百科, or advice on how to get going here?
Thanks!
Well, you probably know about the Books Data API. Since there are no samples for using google-api-java-client
with that API yet (although you can add one and get all your friends to 'star' it so that Google pay attention to it), your basic strategy is:
- download the samples using Mercurial and Maven into your favourite IDE (such as IntelliJ ;- ) It's worth learning Maven/Mercurial or at least how to set them up for your IDE)
- look particularly at the calendar-v2-atom-android-sample
- create some 'model' classes with @Key annotations which mirror the structure of the elements you'll get in the feed using the samples as a guide for how to use them
There unfortunately is no shortcut for coming to terms with the elements of the ATOM 'feed'.
Handy things to know
These include:
- 'everything is an
<entry/>
transport.buildGetRequest().execute().parseAs(MyModel.class)
handles your basic needs- the @Key annotation can handle any namespace prefixes that you gave to your parser when you set it up (xref lines 96-102 of CalendarAndroidSample.java where it sets up the transport and parsers)
Sorry about all the links, but that's what Google development is like!
Colophon
It's best to think of the google-api-java-client
as a tool that helps you with all the ugly XML and HTTP plumbing, so that you can build your own api. It's a bit of work, but once you've mastered the GoogleUrl class (just read the source of it and GenericUrl), and the @Key annotations, there isn't actually a lot of boring work. You get down to tin tacs of 'what do I want to actually do with this information' surprisingly quickly.
精彩评论