- i'm implementing yahoo integration in android retrieving contacts in application.i got xml format url dont know how xml parsing in android . please can me.here code .
private static final string key_contact="contacts"; private static final string key_fields="fields"; private static final string key_type="type"; private static final string key_value="value"; private void getallcontacts() { string host_url = "http://social.yahooapis.com/v1/user/" + muser_guid+ "/contacts"; string nonce = ""+system.currenttimemillis(); string timestamp = ""+(system.currenttimemillis()/1000l); try{ string params = ""+encode("oauth_consumer_key")+"=" + encode(consumer_key) + "&"+encode("oauth_nonce")+"="+encode(nonce) + "&"+encode("oauth_signature_method")+"="+encode("hmac-sha1") + "&"+encode("oauth_timestamp")+"="+encode(timestamp) + "&"+encode("oauth_token")+"="+access_token + "&"+encode("oauth_version")+"="+encode("1.0"); string basestring = encode("get")+"&"+encode(host_url)+"&"+encode(params); string signingkey = encode(consumer_secret)+"&"+encode(access_token_secret); string lsignature = computehmac(basestring, signingkey); lsignature = encode(lsignature); string lrequesturl = host_url + "?oauth_consumer_key="+consumer_key + "&oauth_nonce="+nonce + "&oauth_signature_method=hmac-sha1" + "&oauth_timestamp="+timestamp + "&oauth_token="+access_token + "&oauth_version=1.0" + "&oauth_signature="+lsignature ; httpget httpget = new httpget(lrequesturl); httpclient httpclient = new defaulthttpclient(); responsehandler<string> responsehandler = new basicresponsehandler(); string responsebody = httpclient.execute(httpget, responsehandler); saxparserfactory spf=saxparserfactory.newinstance(); saxparser sp=spf.newsaxparser(); // xmlreader of saxparser created. xmlreader xr=sp.getxmlreader(); inputsource inputsource = new inputsource(); inputsource.setencoding("utf-8"); inputsource.setcharacterstream(new stringreader(responsebody)); xr.parse(inputsource); log.e("xml","reader"); catch(exception e) { e.printstacktrace(); log.e(tag, "error while fetching user contacts"); } } .
if use sax, have create defaulthandler , override methods parsing xml file.
here example http://www.mkyong.com/java/how-to-read-xml-file-in-java-sax-parser/
Comments
Post a Comment