구글 단축 url 생성 > jquery

본문 바로가기
사이트 내 전체검색

jquery

구글 단축 url 생성

페이지 정보

작성자 서방님 댓글 0건 조회 349회 작성일 16-01-22 11:56

본문

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
</head>
<body>

<input type="text" id="longURL"><button id="makeShortURL">단축URL생성</button><br>
<input type="text" id="shortURL">

</body>
<script>
/**
* 단축url 키등록
*/
function load() {
gapi.client.setApiKey('구글 API 키');
gapi.client.load('urlshortener', 'v1',function(){});
}

/**
* 단축 URL생성
*/
$('#makeShortURL').click(function(){
var longURL = $('#longURL').val();
var request = gapi.client.urlshortener.url.insert({
'resource' : {
'longUrl' : longURL
}
});
request.execute(function(response) {
if (response.id != null) {
console.log(response.id);
$('#shortURL').val(response.id);
} else {
alert("error: creating short url");
}
});
});
</script>
<script src="https://apis.google.com/js/client.js?onload=load"></script>
</html>

댓글목록

등록된 댓글이 없습니다.

회원로그인

접속자집계

오늘
24
어제
190
최대
1,347
전체
167,432
Latest Crypto Fear & Greed Index

그누보드5
Copyright © 서방님.kr All rights reserved.