如何使用Google Civic Information API检索特定地点的国会议员?

时间:2017-05-26 08:50:15

标签: api google-api lookup

我尝试在API资源管理器(https://developers.google.com/apis-explorer/?hl=en_US#p/civicinfo/v2/civicinfo.representatives.representativeInfoByAddress)中使用civicinfo.representatives.representativeInfoByAddress端点。

这是我的问题:除了美国众议院外,该终点还会返回所有州,联邦和地方办事处!我可以看到州长,参议员,州参议员,但不是国会议员。我在文档中找不到任何解释为什么这个公然重要的数据被省略的东西,也找不到这些数据的任何替代来源(实际上是当前的)。

为什么Google会扣留国会数据,我该如何获得?这是我从这个API需要的一件事,它似乎从结果中缺失。我试过玩参数和诸如此类的东西,但我找不到那些数据。

必须有办法找到这些信息。在Google API资源管理器中(请参阅上面的链接),尝试输入“WA”作为“地址”字段,并将其他所有内容留空(将下一个设置为TRUE没有区别,其他只是过滤器)。这是返回的数据:

{
 "kind": "civicinfo#representativeInfoResponse",
 "normalizedInput": {
  "line1": "",
  "city": "",
  "state": "WA",
  "zip": ""
 },
 "divisions": {
  "ocd-division/country:us": {
   "name": "United States",
   "officeIndices": [
    0,
    1
   ]
  },
  "ocd-division/country:us/state:wa": {
   "name": "Washington",
   "officeIndices": [
    2,
    3,
    4,
    5,
    6,
    7,
    8,
    9,
    10,
    11
   ]
  }
 },
 "offices": [
  {
   "name": "President of the United States",
   "divisionId": "ocd-division/country:us",
   "levels": [
    "country"
   ],
   "roles": [
    "headOfState",
    "headOfGovernment"
   ],
   "officialIndices": [
    0
   ]
  },
  {
   "name": "Vice-President of the United States",
   "divisionId": "ocd-division/country:us",
   "levels": [
    "country"
   ],
   "roles": [
    "deputyHeadOfGovernment"
   ],
   "officialIndices": [
    1
   ]
  },
  {
   "name": "United States Senate",
   "divisionId": "ocd-division/country:us/state:wa",
   "levels": [
    "country"
   ],
   "roles": [
    "legislatorUpperBody"
   ],
   "officialIndices": [
    2,
    3
   ]
  },
  {
   "name": "Governor",
   "divisionId": "ocd-division/country:us/state:wa",
   "levels": [
    "administrativeArea1"
   ],
   "roles": [
    "headOfGovernment"
   ],
   "officialIndices": [
    4
   ]
  },
  {
   "name": "Lieutenant Governor",
   "divisionId": "ocd-division/country:us/state:wa",
   "levels": [
    "administrativeArea1"
   ],
   "roles": [
    "deputyHeadOfGovernment"
   ],
   "officialIndices": [
    5
   ]
  },
  {
   "name": "State Auditor",
   "divisionId": "ocd-division/country:us/state:wa",
   "officialIndices": [
    6
   ]
  },
  {
   "name": "State Treasurer",
   "divisionId": "ocd-division/country:us/state:wa",
   "officialIndices": [
    7
   ]
  },
  {
   "name": "Attorney General",
   "divisionId": "ocd-division/country:us/state:wa",
   "officialIndices": [
    8
   ]
  },
  {
   "name": "Secretary of State",
   "divisionId": "ocd-division/country:us/state:wa",
   "officialIndices": [
    9
   ]
  },
  {
   "name": "Insurance Commissioner",
   "divisionId": "ocd-division/country:us/state:wa",
   "officialIndices": [
    10
   ]
  },
  {
   "name": "Commissioner of Public Lands",
   "divisionId": "ocd-division/country:us/state:wa",
   "officialIndices": [
    11
   ]
  },
  {
   "name": "State Superintendent of Public Instruction",
   "divisionId": "ocd-division/country:us/state:wa",
   "officialIndices": [
    12
   ]
  }
 ],
 "officials": [
  {
   "name": "Donald J. Trump",
   "address": [
    {
     "line1": "The White House",
     "line2": "1600 Pennsylvania Avenue NW",
     "city": "Washington",
     "state": "DC",
     "zip": "20500"
    }
   ],
   "party": "Republican",
   "phones": [
    "(202) 456-1111"
   ],
   "urls": [
    "http://www.whitehouse.gov/"
   ],
   "photoUrl": "https://www.whitehouse.gov/sites/whitehouse.gov/files/images/45/PE%20Color.jpg",
   "channels": [
    {
     "type": "GooglePlus",
     "id": "+whitehouse"
    },
    {
     "type": "Facebook",
     "id": "whitehouse"
    },
    {
     "type": "Twitter",
     "id": "potus"
    },
    {
     "type": "YouTube",
     "id": "whitehouse"
    }
   ]
  },
  {
   "name": "Mike Pence",
   "address": [
    {
     "line1": "The White House",
     "line2": "1600 Pennsylvania Avenue NW",
     "city": "Washington",
     "state": "DC",
     "zip": "20500"
    }
   ],
   "party": "Republican",
   "phones": [
    "(202) 456-1111"
   ],
   "urls": [
    "http://www.whitehouse.gov/"
   ],
   "photoUrl": "https://www.whitehouse.gov/sites/whitehouse.gov/files/images/45/VPE%20Color.jpg",
   "channels": [
    {
     "type": "GooglePlus",
     "id": "+whitehouse"
    },
    {
     "type": "Facebook",
     "id": "whitehouse"
    },
    {
     "type": "Twitter",
     "id": "VP"
    }
   ]
  },
  {
   "name": "Maria Cantwell",
   "address": [
    {
     "line1": "511 Hart Senate Office Building",
     "city": "Washington",
     "state": "DC",
     "zip": "20510"
    }
   ],
   "party": "Democratic",
   "phones": [
    "(202) 224-3441"
   ],
   "urls": [
    "https://www.cantwell.senate.gov/"
   ],
   "photoUrl": "http://bioguide.congress.gov/bioguide/photo/C/C000127.jpg",
   "channels": [
    {
     "type": "Facebook",
     "id": "senatorcantwell"
    },
    {
     "type": "Twitter",
     "id": "senatorcantwell"
    },
    {
     "type": "YouTube",
     "id": "SenatorCantwell"
    }
   ]
  },
  {
   "name": "Patty Murray",
   "address": [
    {
     "line1": "154 Russell Senate Office Building",
     "city": "Washington",
     "state": "DC",
     "zip": "20510"
    }
   ],
   "party": "Democratic",
   "phones": [
    "(202) 224-2621"
   ],
   "urls": [
    "http://www.murray.senate.gov/public/"
   ],
   "photoUrl": "http://bioguide.congress.gov/bioguide/photo/M/M001111.jpg",
   "channels": [
    {
     "type": "GooglePlus",
     "id": "+pattymurray"
    },
    {
     "type": "Twitter",
     "id": "pattymurray"
    },
    {
     "type": "YouTube",
     "id": "SenatorPattyMurray"
    },
    {
     "type": "Facebook",
     "id": "pattymurray"
    },
    {
     "type": "YouTube",
     "id": "pattymurray"
    }
   ]
  },
  {
   "name": "Jay Inslee",
   "address": [
    {
     "line1": "PO Box 40002",
     "city": "Olympia",
     "state": "WA",
     "zip": "98504"
    }
   ],
   "party": "Democratic",
   "phones": [
    "(360) 902-4111"
   ],
   "urls": [
    "http://www.governor.wa.gov/"
   ],
   "photoUrl": "http://www.governor.wa.gov/sites/default/files/images/720px-for-web_0.jpg",
   "emails": [
    "Governor.JayInslee@governor.wa.gov"
   ],
   "channels": [
    {
     "type": "Facebook",
     "id": "WaStateGov"
    },
    {
     "type": "Twitter",
     "id": "GovInslee"
    },
    {
     "type": "YouTube",
     "id": "UCJhWBqWVdVnPro7tx2t7j3w"
    }
   ]
  },
  {
   "name": "Cyrus Habib",
   "address": [
    {
     "line1": "PO Box 40400",
     "city": "Olympia",
     "state": "WA",
     "zip": "98504"
    }
   ],
   "party": "Democratic",
   "phones": [
    "(360) 786-7700"
   ],
   "urls": [
    "http://www.ltgov.wa.gov/"
   ],
   "photoUrl": "http://www.ltgov.wa.gov/wp-content/uploads/2017/01/Senator-Habib-2015_CROPPED-225x300.jpg",
   "emails": [
    "ltgov@ltgov.wa.gov"
   ],
   "channels": [
    {
     "type": "Twitter",
     "id": "waltgov"
    },
    {
     "type": "Facebook",
     "id": "Lt-Governor-Cyrus-Habib-347384975292728"
    }
   ]
  },
  {
   "name": "Pat (Patrice) McCarthy",
   "address": [
    {
     "line1": "Insurance Building Capitol Campus",
     "line2": "302 Sid Snyder Avenue SW",
     "city": "Olympia",
     "state": "WA",
     "zip": "98504"
    }
   ],
   "party": "Democratic",
   "phones": [
    "(360) 902-0370"
   ]
  },
  {
   "name": "Duane Davidson",
   "address": [
    {
     "line1": "PO Box 40200",
     "city": "Olympia",
     "state": "WA",
     "zip": "98504"
    }
   ],
   "party": "Republican",
   "phones": [
    "(360) 902-9001"
   ]
  },
  {
   "name": "Bob Ferguson",
   "address": [
    {
     "line1": "PO Box 40100",
     "city": "Olympia",
     "state": "WA",
     "zip": "98504"
    }
   ],
   "party": "Democratic",
   "phones": [
    "(360) 753-6200"
   ],
   "urls": [
    "http://www.atg.wa.gov/"
   ],
   "channels": [
    {
     "type": "Facebook",
     "id": "WAStateAttorneyGeneral"
    },
    {
     "type": "Twitter",
     "id": "AGOWA"
    }
   ]
  },
  {
   "name": "Kim Wyman",
   "address": [
    {
     "line1": "PO Box 40220",
     "city": "Olympia",
     "state": "WA",
     "zip": "98504"
    }
   ],
   "party": "Republican",
   "phones": [
    "(360) 902-4151"
   ],
   "urls": [
    "http://www.sos.wa.gov/"
   ],
   "emails": [
    "kim.wyman@sos.wa.gov"
   ],
   "channels": [
    {
     "type": "Facebook",
     "id": "WaSecretaryOfState"
    },
    {
     "type": "Twitter",
     "id": "secstatewa"
    }
   ]
  },
  {
   "name": "Mike Kreidler",
   "party": "Democratic",
   "phones": [
    "(360) 725-7000"
   ],
   "urls": [
    "http://www.insurance.wa.gov/"
   ],
   "channels": [
    {
     "type": "Facebook",
     "id": "wsoic"
    },
    {
     "type": "Twitter",
     "id": "WAinsuranceblog"
    }
   ]
  },
  {
   "name": "Hilary Franz",
   "address": [
    {
     "line1": "PO Box 47000",
     "city": "Olympia",
     "state": "WA",
     "zip": "98504"
    }
   ],
   "party": "Democratic",
   "phones": [
    "(360) 902-1000"
   ]
  },
  {
   "name": "Chris Reykdal",
   "address": [
    {
     "line1": "Mail stop: 47200 Old Capitol Building P.O. Box 47200",
     "city": "Olympia",
     "state": "WA",
     "zip": "98504"
    }
   ],
   "party": "Nonpartisan",
   "phones": [
    "(360) 725-6115"
   ]
  }
 ]
}

现在,在该JSON中搜索“Adam Smith”。他是西澳大利亚州的现任成员。您会注意到字符串不存在,国会的任何其他成员也不存在,也无法在返回时找到任何参考链接来查找它们。

我错过了什么?对我来说似乎完全疯了,除了美国众议院的成员之外,其他所有内容都包括在内(但包括联邦和州参议院)。这意味着数据有可能以某种方式提供,但我只是不知道它。有人可以帮忙吗?

谢谢!

2 个答案:

答案 0 :(得分:2)

这已经晚了几个月,但您需要指定查找角色legislatorUpperBodylegislatorLowerBody

如果您只想拥有这两个信息,请尝试运行查询

https://www.googleapis.com/civicinfo/v2/representatives?address=[address]&levels=country&roles=legislatorUpperBody&roles=legislatorLowerBody&key=[api_key]

答案 1 :(得分:0)

API似乎没有返回代表给定区域的所有可能结果,而是仅返回了完全匹配的结果。

假设2个请求都使用levels=country&roles=legislatorLowerBody

我使用地址Boston, MA得到0个结果。

我使用地址10 Summer St, Boston, MA找到合适的代表。

国会选区可能非常具体。在某些情况下,同一条街道上的街道编号将决定一个地区与另一个地区的联系。