Android: Accessing the Google Products Search within your Android-Application -
i wanna use gdata apis within android application. being more specific wanna give user ability search keywords, use gdata api search products within googleproducts these keywords , parse xml back.
i know how parse xml files via org.xml.sax.helpers.defaulthandler guess not suppose use such handler rather rely on gdata api parse xml me.
my problem dont know how integrate api in app. there similiar topic within stackoverflow (hier) not @ satisfied answer gave. giving information "look @ our announced version 2.1.0-alpha of gdata java library supports android" doesnt quite me integrate gdata in app.
i appreciate if give step-by-step guide how integrate gdata api within app, including code examples make search-request , parsing results google products.
after days of research found solution:
google gives introduction on how access items saved on google base (hier).surprisingly don't need implement google data base apis or access google product, can query them via plain url.
you can access public items within google base , google products via url http://www.google.com/base/feeds/snippets . can append specific queries on url, example: ?bq=digital+camera searches digital camera or ?bq=5030932067876 searches actual ean code.
you xml-document holds result of query. example url http://www.google.com/base/feeds/snippets?bq=5030932067876 gives following xml-document:
<?xml version='1.0' encoding='utf-8'?> <feed xmlns='http://www.w3.org/2005/atom' xmlns:opensearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:gm='http://base.google.com/ns-metadata/1.0' xmlns:g='http://base.google.com/ns/1.0' xmlns:batch='http://schemas.google.com/gdata/batch'> <id>http://www.google.com/base/feeds/snippets</id> <updated>2010-07-27t15:52:29.459z</updated> <title type='text'>items matching query: 5030932067876</title> <link rel='alternate' type='text/html' href='http://base.google.com'/> <link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://www.google.com/base/feeds/snippets'/> <link rel='http://schemas.google.com/g/2005#batch' type='application/atom+xml' href='http://www.google.com/base/feeds/snippets/batch'/> <link rel='self' type='application/atom+xml' href='http://www.google.com/base/feeds/snippets?start-index=1&max-results=25&bq=5030932067876'/> <author> <name>google inc.</name> <email>base@google.com</email> </author> <generator version='1.0' uri='http://base.google.com'>googlebase</generator> <opensearch:totalresults>20</opensearch:totalresults> <opensearch:startindex>1</opensearch:startindex> <opensearch:itemsperpage>25</opensearch:itemsperpage> <entry> <id>http://www.google.com/base/feeds/snippets/6567855098786723080</id> <published>2009-06-17t19:10:11.000z</published> <updated>2010-07-26t19:36:16.000z</updated> <category scheme='http://base.google.com/categories/itemtypes' term='produkte'/> <title type='text'>xb360 fifa 09 electronic arts ead07606316 5030932067876</title> <content type='html'>fifa 09 die brandneue fußballsimulation! geh in fifa 09 auf den platz und spiel professionellen fußball, wie du ihn dir vorstellst. erlebe die authentischste fußballsimulation, die ea sports? je veröffentlicht hat, lebe deinen traum vom ...</content> <link rel='alternate' type='text/html' href='http://www.mercateo.com/p/615it-r78802/xb360_fifa_09.html?pageid=fg-615it-r78802'/> <link rel='self' type='application/atom+xml' href='http://www.google.com/base/feeds/snippets/6567855098786723080'/> <author> <name>mercateo.com</name> </author> <g:zustand type='text'>neu</g:zustand> <g:mpn type='text'>ead07606316</g:mpn> <g:image_link type='url'>http://images.mercateo.com/images/products/voelkner/906692_bb_00_fb.eps.jpg</g:image_link> <g:item_language type='text'>de</g:item_language> <g:ean type='text'>5030932067876</g:ean> <g:id type='text'>615it-r78802</g:id> <g:shipping type='shipping'> <g:price>4.76 eur</g:price> </g:shipping> <g:target_country type='text'>de</g:target_country> <g:preis type='floatunit'>34.14 eur</g:preis> <g:expiration_date type='datetime'>2010-08-25t19:36:16z</g:expiration_date> <g:marke type='text'>electronic arts</g:marke> <g:customer_id type='int'>114950</g:customer_id> <g:item_type type='text'>produkte</g:item_type> </entry>
(... more entrys come...)
you can parse document doing following: subclass org.xml.sax.helpers.defaulthandler. , initialize myhandler following code (import javax.xml.parsers.saxparser , javax.xml.parsers.saxparserfactory make work):
myhandler myhandler = new myhandler(); string urlstring = "http://www.google.com/base/feeds/snippets?bq=5030932067876"; url link = new url(urlstring); saxparserfactory spf = saxparserfactory.newinstance(); saxparser sp = spf.newsaxparser(); xmlreader xr = sp.getxmlreader(); xr.setcontenthandler(myhandler); inputstream stream = link.openstream(); inputsource inputsource = new inputsource(stream); inputsource.setencoding("iso-8859-1"); xr.parse(inputsource);
depending on how subclassed myhandler, object myhandler should have values parsed in.
hope helps someone!
Comments
Post a Comment