2009-07-07 11 views
5

zillow라는 웹 사이트에서 API를 가져 오려고 노력하고 있습니다. 그러나 나는 웹에 새로운 방식입니다. 그들은 그것을 사용하는 방법을 here 시도하고 설명하지만, 그래서 내가 그들의 포럼을 보니 길을 잃었을했다. 누군가가 거기에 "예제"를 올렸지 만 코드가 어디에서 API를 호출하는지 알 수 없습니다. 기본적으로 내가 여기 당신은 그것을 볼 수있는 사람의 예에서 가져온 소스 코드,zillow.com API를 사용하여 데이터를 API 호출로 보내고 가져 오는 방법

<html xml:lang="en" lang="en"> 
<head> 
    <title></title> 
</head> 
<body> 
<h3><font face="Verdana, Arial, Helvetica, sans-serif">Get Property < # >Zestimates 
    from Zillow</a></font></h3> 
<form method="post" action="/Real-Estate/Zestimate.php" name="zip_search"> 
    <table align="center" width="618"> 
    <tr> 
     <td colspan="2"><font face="verdana, arial, sans-serif">Please specify the 
     Property address. </font></td> 

     <td width="205" align="left"> <div align="left"><font face="Verdana, Arial, Helvetica, sans-serif"><#></a></font></div></td> 
    </tr> 
    <tr> 
     <td colspan="2"><font face="Verdana, Arial, Helvetica, sans-serif">Street</font>: 
     <input id="street2" type="text" maxlength="50" size="50" value="" name="street"/></td> 
     <td>&nbsp;</td> 
    </tr> 
    <tr> 
     <td colspan="2"><font face="verdana, arial, sans-serif">City, State or ZipCode:</font> 
     <input id="citystatezip3" type="text" maxlength="50" size="20" value="" name="citystatezip"/></td> 

     <td>&nbsp; </td> 
    </tr> 

    </table> 
    <div align="center"> 
    <input name="submit" type="submit" value="Get Zestimate"> 
    </div> 
</form> 

는 단순한 형태이다, 주소하고 다시 데이터를 얻기 위해 그 정보를 보내드립니다 양식 필드를 취할 필요가 게시물 자체가 옳은가요? 그러나 내가 API를 사용하여 데이터를 가져와 표시하지만 API가 표시되지는 않습니다. 나는 당신이 제공 할 수있는 어떤 도움이라도 원합니다, 고마워요!

+0

당신이 말하는 포럼 게시물에 연결할 수 있습니까? –

답변

5

http://www.zillow.com/howto/api/APIFAQ.htm#devkit을 기준으로 볼 때 JavaScript API는 없습니다. 이 (및 도메인 간 제한) 때문에 서버 측 언어를 사용해야합니다. 간단한 Java 예제를 추가하겠습니다.

편집 : 좋아요, 여기 있습니다. 그것은 단지 거리 주소와 도시/주를 취하고 서식이 지정된 값을 반환합니다. 오류 검사 남겨 :

import java.text.NumberFormat; 

import org.w3c.dom.*; 
import org.xml.sax.*; 

import javax.xml.parsers.*; 

import javax.xml.transform.*; 
import javax.xml.transform.dom.*; 
import javax.xml.transform.stream.*; 

import java.io.*; 

import java.util.Currency; 

public class Zillow 
{ 
    private static final DocumentBuilderFactory dbFac; 
    private static final DocumentBuilder docBuilder; 
    static 
    { 
     try 
     { 
      dbFac = DocumentBuilderFactory.newInstance(); 
      docBuilder = dbFac.newDocumentBuilder(); 
     } 
     catch(ParserConfigurationException e) 
     { 
      throw new RuntimeException(e); 
     } 
    } 
    private static final String DEEP_URL = "http://www.zillow.com/webservice/GetDeepSearchResults.htm"; 
    private static final String ZESTIMATE_URL = "http://www.zillow.com/webservice/GetZestimate.htm"; 

    private static final String ZWSID = ...; 

    private static final NumberFormat nf = NumberFormat.getCurrencyInstance(); 

    // Returns Zestimate value for address. 
    public static String getValuation(String address, String cityStateZip) throws SAXException, IOException 
    { 
     Document deepDoc = docBuilder.parse(DEEP_URL + 
             "?zws-id=" + ZWSID + 
             "&address=" + address + 
             "&citystatezip=" + cityStateZip); 
     Element firstResult = (Element)deepDoc.getElementsByTagName("result").item(0); 
     String zpid = firstResult.getElementsByTagName("zpid").item(0).getTextContent(); 
     Document valueDoc = docBuilder.parse(ZESTIMATE_URL + 
              "?zws-id=" + ZWSID + 
              "&zpid=" + zpid); 
     Element zestimate = (Element)valueDoc.getElementsByTagName("zestimate").item(0); 
     Element amount = (Element)zestimate.getElementsByTagName("amount").item(0); 
     String currency = amount.getAttribute("currency"); 
     nf.setCurrency(Currency.getInstance(currency)); 
     return nf.format(Double.parseDouble(amount.getTextContent())); 
    } 

    public static void main(String[] args) throws Throwable 
    { 
     String address = args[0]; 
     String cityStateZip = args[1]; 
     System.out.println(getValuation(address, cityStateZip)); 
    } 
} 
+0

굉장한 남자, 고마워. 필자는 PHP를 사용하여 더 잘 알고 있으므로이 작업을 수행했습니다. – thatryan

+3

차가움. 이후의 검색자를 위해 PHP 코드를 게시 할 수 있습니다. –

+1

Matthew Flaschen에게 감사드립니다. 당신은 완전한 자바 코드를주었습니다. 같은 수정 작업없이 잘 사용했습니다. 굉장해! 나는 upvoting하고있다. .. –

0

이 Nahhh ...이 방법이 훨씬

빌드 두 가지 기능 :-) 쉽고 Zillow를 위해 다음과 같이 사용할 수 있습니다. 되돌아 오는 응답은 매우 명백합니다.

string zWsid = "yourZwsid"; 
// sample API Call 
// http://www.zillow.com/webservice/GetSearchResults.htm?zws-id=<ZWSID>&address=2114+Bigelow+Ave&citystatezip=Seattle%2C+WA 

string response = string.Empty; 
int iZpid = 0; 
int iLotSizeSqFoot = 0; 
int iHomeValue = 0; 
float estimate = 0; 

try { 
    response = web_url("http://www.zillow.com/webservice/GetSearchResults.htm?zws-id=" + zWsid + "&address=" + addressTB.Text + "&citystatezip=" + CityStateZipTB.Text); 
} catch (Exception ex) { 
    MessageBox.Show("Exception occured! " + ex.ToString()); 
} 


// MessageBox.Show(response); 
try { 
    iZpid = Int32.Parse(parseTag(response, "zpid")); 
} 


/// you can make a lot of the calls and catch a lot of the values back just like this :-) 

///// Functions///// 

private string parseTag(string response, string tag) { 

    XmlDocument doc = new XmlDocument(); 
    doc.LoadXml(response); 
    XmlNodeList elemList = doc.GetElementsByTagName(tag); 
    string parsedTag = elemList[0].InnerXml; 
    return parsedTag; 

} 

private string web_url(string url) { 

    // Create a request for the URL. 
    WebRequest request = WebRequest.Create(url); 

    // If required by the server, set the credentials. 
    request.Credentials = CredentialCache.DefaultCredentials; 

    // Get the response. 
    WebResponse response = request.GetResponse(); 

    // Display the status. 
    // MessageBox.Show(((HttpWebResponse)response).StatusDescription); 
    // Get the stream containing content returned by the server. 
    Stream dataStream = response.GetResponseStream(); 

    // Open the stream using a StreamReader for easy access. 
    StreamReader reader = new StreamReader(dataStream); 

    // Read the content. 
    string responseFromServer = reader.ReadToEnd(); 

    // Display the content. 
    // MessageBox.Show(responseFromServer); 
    // Clean up the streams and the response. 
    reader.Close(); 
    response.Close(); 

    return responseFromServer; 
} 
관련 문제