習得条件:JS get APIを介して、例えば、元のURLにgoo.gl URLを回すのさまざまな方法のためのドキュメントがたくさんありますhttps://code.google.com/apis/console/jsでURLを短くするにはどうすればよいですか?
でurlshortenerためのAPIキーを自分で作成:here、hereとhereは - 少なくとも最初のものは動作します。
私が代わりに{ "longUrl": "https://codepen.io/" }
を渡し、に小さなURLをURL を変換するinsert APIを使用するために、ほんの少しその1を微調整する場合は、しかし、それが壊れます。あなたが好きならhttp://codepen.io/johan/full/EHbGy#YOUR-API-KEY-HEREでそれを試してみるか、このどこかを実行します。
<script>
var api_key = 'YOUR-API-KEY-HERE';
function makeRequest() {
var request = gapi.client.urlshortener.url.insert({
'longUrl': 'https://codepen.io/'
});
request.execute(function(response) {
alert(JSON.stringify(window.got = response));
});
}
function load() {
gapi.client.setApiKey(api_key);
gapi.client.load('urlshortener', 'v1', makeRequest);
}
</script>
<script src="https://apis.google.com/js/client.js?onload=load"></script>
...それだけでエラーで応答します。
{ "code": 400
, "message": "Required"
, "data":
[ { "domain": "global"
, "reason": "required"
, "message": "Required"
, "locationType": "parameter"
, "location": "resource.longUrl"
}
]
, "error":
{ "code": 400
, "message": "Required"
, "data":
[ { "domain": "global"
, "reason": "required"
, "message": "Required"
, "locationType": "parameter"
, "location": "resource.longUrl"
}
]
}
}
提案を? (いいえ、resource.longUrl
キーを持つオブジェクトにurl.insert
パラメータを変更するか、ラッパーオブジェクトなしでURLを渡すだけでうまくいきません)。
ありがとうございました!良いドキュメントを維持することは、良いAPIを作ることと同じくらい難しいことです。 – ecmanaut
@ecmanaut 'URL Resource'の例へのこのリンクは役に立ちませんでしたか? https://developers.google.com/url-shortener/v1/url/url#resource – doublesharp
developers.google.comでは、他のユーザーと協力して404サイトを整理することができます。私はそれが絶え間ない完全なQAの立場であることが分かりました。 – ecmanaut