-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathrequestSample.html
executable file
·87 lines (75 loc) · 3.05 KB
/
requestSample.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<!--
Copyright (c) 2011 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy of
the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations under
the License.
To run this sample, replace YOUR API KEY with your application's API key.
It can be found at https://code.google.com/apis/console/?api=plus under API Access.
-->
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' />
<style>
#info {
border: 1px solid black;
padding: 0.25em;
}
</style>
<script>
// Enter the API key from the Google Develoepr Console - to handle any unauthenticated
// requests in the code.
// The provided key works for this sample only when run from
// https://google-api-javascript-client.googlecode.com/hg/samples/requestSample.html
// To use in your own application, replace this API key with your own.
var apiKey = 'AIzaSyAdjHPT5Pb7Nu56WJ_nlrMGOAgUAtKjiPM';
function handleClientLoad() {
gapi.load('client', makeRequest);
}
function initClient() {
gapi.client.init({
apiKey: apiKey,
}).then(makeRequest)
}
function makeRequest() {
gapi.client.setApiKey(apiKey);
function writeResponse(resp) {
var responseText;
if (resp.error && resp.error.errors[0].debugInfo == 'QuotaState: BLOCKED') {
responseText = 'Invalid API key provided. Please replace the "apiKey" value with your own.';
} else {
responseText = 'Short URL ' + shortUrl + ' expands to ' + resp.longUrl;
}
var infoDiv = document.getElementById('info');
infoDiv.innerHTML = '';
infoDiv.appendChild(document.createTextNode(responseText));
}
var shortUrl = document.getElementById('shortUrl').value;
var restRequest = gapi.client.request({
'path': '/urlshortener/v1/url',
'params' : {'shortUrl' : shortUrl}
});
restRequest.execute(writeResponse);
}
</script>
<script async defer src="https://apis.google.com/js/api.js"
onload="this.onload=function(){};handleClientLoad();"
onreadystatechange="if (this.readyState === 'complete') this.onload();">
</script>
</head>
<body>
<p>Enter a short URL and click "Expand URL" to get the full URL.</p>
<label for="shortUrl">Short URL </label>
<input id="shortUrl" type="text" value="http://goo.gl/fbsS" />
<button onclick="makeRequest();">
Expand URL
</button>
<div style="margin-top:0.5em;"><span id="info">Results</span></div>
</body>
</html>