簡體   English   中英

無法弄清楚如何正確使用API

[英]Cannot Figure out how to Properly Use APIs

因此,我正在嘗試創建一個網站,向本地議員發送一封信。 該網站主要由以下表格組成:點擊“提交”后,該表格應返回代表以使用Google Civic Info API進行聯系。 我對HTTP通訊還很陌生,所以我不確定為什么在嘗試使用GET時出現403錯誤。

我什至不知道我是否正確使用了API。 此處的目標是提交地址(以及其他信息),將數據發送到API,並根據用戶提交的信息返回議員。

鏈接到Google Civic Info API: https//developers.google.com/civic-information/docs/v2/representatives/representativeInfoByAddress

我的代碼:

<!DOCTYPE html>

<html>

<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content = "IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<title>Lob Application</title>

<link href = "stylesheet.css" rel = "stylesheet" >
</head>

<body>
 <div id = formInput class = "container-fluid">
 <form name = "submitDataForm" method = "GET" onsubmit="getData()">
  Name:<br>
    <input type = "text" name = "name"><br>
  Address Line 1:<br>
    <input type = "text" name = "addressLineOne"><br>
  Address Line 2:<br>
    <input type = "text" name = "addressLineTwo"><br>
  City:<br>
    <input type = "text" name = "city"><br>
  State:<br>
    <input type = "text" name = "state"><br>
  Zip Code:<br>
    <input type = "text" name = "zip"><br>
  Message:<br>
    <input type = "text" name = "message"/><br>
  <input id = "submit" type = "submit" value = "Submit"/>
</form>
</div>
<script src="processData.js" type = "text/javascript"></script>
</body>
</html>

Javascript:

function getData(){
var xhr = new XMLHttpRequest()
xhr.open("GET", "https://www.googleapis.com/civicinfo/v2/representatives/", false);
xhr.send(null);
console.log(xhr.status);
console.log(xhr.statusText);
}

看來您已達到API使用量的每日配額限制。 您必須通過Google Developers Console進行注冊並獲得有效的API_KEY。

請查看此內容以了解您的錯誤消息,並查看此頁面以了解如何使用API

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM