开发者

want to access google books from android app

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:

  1. 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)
  2. look particularly at the calendar-v2-atom-android-sample
  3. 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:

  1. 'everything is an <entry/>
  2. transport.buildGetRequest().execute().parseAs(MyModel.class) handles your basic needs
  3. 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜