如何使用 zillow.com API 将数据发送到 API 调用并取回 [英] How to send data to an API call and get it back, using zillow.com API

查看:24
本文介绍了如何使用 zillow.com API 将数据发送到 API 调用并取回的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从为我工作的名为 zillow 的网站获取 API,但我对网络内容很陌生.他们尝试在这里解释如何使用它,但它让我迷失了方向,所以我看了他们的论坛.有人在那里发布了一个示例",但我看不到他们的代码甚至在哪里调用 API.基本上我需要一个表单字段,它将是一个地址并发送该信息以取回数据,这是从家伙示例中获取的源代码,

<头><title></title><身体><h3><font face="Verdana, Arial, Helvetica, sans-serif">获取属性 <# >Zestimates来自 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">请指定物业地址.</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">城市、州或邮政编码:</font><input id="citystatezip3" type="text" maxlength="50" size="20" value="" name="citystatezip"/></td><td>&nbsp;</td></tr><div align="center"><input name="submit" type="submit" value="Get Zestimate">

</表单>

您可以看到它只是一个简单的表单,可以发布给自己,对吗?但是当我点击 go 时,它从 API 中提取数据并显示它,但我不知道如何.我希望您能提供任何帮助,谢谢!

解决方案

基于 http://www.zillow.com/howto/api/APIFAQ.htm#devkit,没有 JavaScript API.因此(以及跨域限制),您必须使用服务器端语言.我将添加一个简单的 Java 示例.

好的,开始了.它只需要街道地址和城市/州,并返回一个格式化的值.错误检查被遗漏了:

import java.text.NumberFormat;导入 org.w3c.dom.*;导入 org.xml.sax.*;导入 javax.xml.parsers.*;导入 javax.xml.transform.*;导入 javax.xml.transform.dom.*;导入 javax.xml.transform.stream.*;导入 java.io.*;导入 java.util.Currency;公开课 Zillow{私有静态最终 DocumentBuilderFactory dbFac;私有静态最终 DocumentBuilder docBuilder;静止的{尝试{dbFac = DocumentBuilderFactory.newInstance();docBuilder = dbFac.newDocumentBuilder();}catch(ParserConfigurationException e){抛出新的运行时异常(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";私有静态最终字符串 ZWSID = ...;private static final NumberFormat nf = NumberFormat.getCurrencyInstance();//返回地址的 Zestimate 值.public static String getValuation(String address, String cityStateZip) 抛出 SAXException, IOException{文档 deepDoc = docBuilder.parse(DEEP_URL +"?zws-id=" + ZWSID +"&address=" + 地址 +"&citystatezip=" + cityStateZip);元素 firstResult = (Element)deepDoc.getElementsByTagName("result").item(0);String zpid = firstResult.getElementsByTagName("zpid").item(0).getTextContent();文档值Doc = docBuilder.parse(ZESTIMATE_URL +"?zws-id=" + ZWSID +"&zpid=" + zpid);元素 zestimate = (Element)valueDoc.getElementsByTagName("zestimate").item(0);元素数量 = (Element)zestimate.getElementsByTagName("amount").item(0);String currency = amount.getAttribute("currency");nf.setCurrency(Currency.getInstance(currency));返回 nf.format(Double.parseDouble(amount.getTextContent()));}public static void main(String[] args) 抛出 Throwable{字符串地址 = args[0];字符串 cityStateZip = args[1];System.out.println(getValuation(address, cityStateZip));}}

I am trying to get the API from a website called zillow working for me, but I am way new to web stuff. They try and explain here how to use it, but it had me lost so I looked in their forums. Someone posted an "example" there, but I can not see where their code even calls the API. Basically I need to take a form field that will be an address and send that info to get data back, here is the source code taken from the guys example,

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

You can see it is just a simple form that posts to itself right? But when I hit go it pulls the data from the API and displays it, but I do not see how. I would love any help you can offer, thank you!

解决方案

Based on http://www.zillow.com/howto/api/APIFAQ.htm#devkit, there is no JavaScript API. Because of this (and cross-domain restrictions) you have to use a server-side language. I'll add a simple Java example.

EDIT: Okay, here goes. It just takes the street address and city/state, and returns a formatted value. Error-checking left out:

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

这篇关于如何使用 zillow.com API 将数据发送到 API 调用并取回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆