2010-07-26 3 views
0

Android 애플리케이션 내에서 Gdata API를 사용하고 싶습니다. 좀 더 구체적으로 말하자면 사용자에게 키워드 검색 기능을 제공하고, Gdata API를 사용하여 googleproducts 내에서 이들 키워드에 대한 제품을 검색하고 내가 얻은 XML을 파싱합니다.Android : Android 애플리케이션 내 Google 제품 검색에 액세스

org.xml.sax.helpers.DefaultHandler를 통해 xml 파일을 구문 분석하는 방법을 알고 있지만 이러한 처리기를 사용하는 대신 Gdata API를 사용하여 XML을 구문 분석해야합니다.

내 문제는 내가 내 애플 리케이션에서 API를 통합하는 방법을 모른다. stackoverflow (hier) 내에 비슷한 주제가 있지만 나는 그들이 제공 한 대답에 전혀 만족하지 않는다. "Android를 지원하는 GData Java 라이브러리의 최근에 발표 된 버전 2.1.0-alpha를 보면"내 정보에 gdata를 통합하는 데 도움이되지 않습니다.

내 앱에서 gdata API를 통합하는 방법에 대한 단계별 가이드를 제공 할 수 있으면 고맙겠습니다. 코드 예제를 통해 검색 요청을하고 Google 제품에서 결과를 파싱합니다.

구글이 구글베이스 (hier)에 저장된 항목에 액세스하는 방법에 대한 소개를 제공 .Surprisingly 어떤 Google 데이터베이스 API를 구현 할 필요가 없습니다 :

답변

3

연구의 몇 일 후에 나는 마침내 해결책을 발견 또는 Google 제품에 액세스하기위한 항목이 있으면 일반 URL을 통해 쉽게 쿼리 할 수 ​​있습니다.

http://www.google.com/base/feeds/snippets을 통해 Google Base 및 Google 제품의 공개 항목에 액세스 할 수 있습니다. 이 URL에 특정 검색어를 추가 할 수 있습니다 (예 :? bq = digital + camera). 디지털 카메라를 검색하는 경우 또는? bq = 5030932067876이면 실제 EAN 코드를 검색합니다.

해당 쿼리의 결과를 보유한 XML 문서가 다시 제공됩니다.

<?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&amp;max-results=25&amp;bq=5030932067876'/> 
    <author> 
     <name>Google Inc.</name> 
     <email>[email protected]</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, so 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> 

당신은 단지 다음을 수행하여이 내용을 구문 분석 할 수 있습니다 (... 더 져야 할 엔트리가 ... 올) : 다음을 하위 클래스 예를 들어, URL http://www.google.com/base/feeds/snippets?bq=5030932067876는 다음과 같은 XML-문서를 다시 제공 org.xml.sax.helpers.DefaultHandler. 그리고 (작동하도록 수입 javax.xml.parsers.SAXParser 및을 javax.xml.parsers.SAXParserFactory) 다음 코드로 myHandler가 초기화 :

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); 

이가 MyHandler를 서브 클래 싱 방법에 따라 개체 myHandler가 모두 있어야한다 방금 파싱 한 값입니다.

희망이 있으면 도움이됩니다.

관련 문제