2016-09-29 17 views
0

地元の議員に手紙を送るウェブサイトを作成しようとしています。このウェブサイトは主に、「送信」をクリックすると、Google Civic Info APIを使用して連絡を取る担当者に返信するフォームで構成されています。私はHTTP通信にはまだまだ慣れていないので、GETを使用しようとすると、なぜ403エラーが発生するのかわかりません。APIを正しく使用する方法がわからない

APIを正しく使用しているかどうかわかりません。ここでの目標は、アドレスを(追加情報とともに)提出し、そのデータをAPIに送信し、ユーザーの提出された情報に基づいて議員を返させることです。 Googleのシビック情報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); 
} 

答えて

0

あなたのAPIを使用するための毎日のクォータ制限に達したようです。 Googleデベロッパーコンソールにお申し込みいただき、有効なAPI_KEYを取得する必要があります。

API

の使用方法を理解するために、あなたのエラーメッセージを理解するためと this pagethisを見てみましょう
関連する問題