0
<html>
<head>
<script>
function appendResults(text) {
var results = document.getElementById('results');
results.appendChild(document.createElement('P'));
results.appendChild(document.createTextNode(text));
}
function makeRequest() {
var request = gapi.client.urlshortener.url.get({
'shortUrl': 'http://goo.gl/fbsS'
});
request.then(function(response) {
appendResults(response.result.longUrl);
}, function(reason) {
console.log('Error: ' + reason.result.error.message);
});
}
function init() {
gapi.client.setApiKey('*My API key*');
gapi.client.load('urlshortener', 'v1').then(makeRequest);
}
</script>
<script src="https://apis.google.com/js/client.js?onload=init"></script>
</head>
<body>
<div id="results"></div>
</body>
</html>
这是入门页的示例代码使用谷歌翻译API here。我完全按照指示使用它,并且我已经使用API密钥更改了“API密钥”部分。谁能告诉我为什么这个代码不起作用?是否有任何其他库需要导入到.html文件中?如何访问谷歌翻译API
您是否在控制台中看到任何错误? – vrijdenker 2014-10-04 14:20:08
不,只是一个空白页 – Heisenberg 2014-10-04 14:20:31
我想那是因为你没有翻译任何东西。你期望它做什么? – vrijdenker 2014-10-04 16:22:06