2026, 새로운 도약을 시작합니다.

구글 단축 주소

· 9년 전 · 3655 · 2

[code]

<? 

class googl {
    function googl($key,$apiURL = 'https://www.googleapis.com/urlshortener/v1/url') {
        $this->apiURL = $apiURL.'?key='.$key;
    }
    function shorten($url) {
        $response = $this->send($url);
        return isset($response['id']) ? $response['id'] : false;
    }
    function expand($url) {
        $response = $this->send($url,false);
        return isset($response['longUrl']) ? $response['longUrl'] : false;
    }
    function send($url,$shorten = true) {
        $ch = curl_init();
        if($shorten) {
            curl_setopt($ch,CURLOPT_URL,$this->apiURL);
            curl_setopt($ch,CURLOPT_POST,1);
            curl_setopt($ch,CURLOPT_POSTFIELDS,json_encode(array("longUrl"=>$url)));
            curl_setopt($ch,CURLOPT_HTTPHEADER,array("Content-Type: application/json"));
        }
        else {
            curl_setopt($ch,CURLOPT_URL,$this->apiURL.'&shortUrl='.$url);
        }
        curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
        $result = curl_exec($ch);
        curl_close($ch);
        return json_decode($result,true);
    }       
}

$key = $config[cf_googl_shorturl_apikey]; // 구글 API Key
$googl = new googl($key);
//$sUrl = googl_short_url($url);
$sUrl = $googl->shorten("http://multime.kr/");
$eUrl = $googl->expand($sUrl);
echo "$sUrl<br>$eUrl";

?> 

[/code] 

|

댓글 2개

마침 필요했었는데 감사합니다.
구글 단축 URL API 사용방법 (Javascript) : https://goo.gl/hU42mG

댓글 작성

댓글을 작성하시려면 로그인이 필요합니다.

로그인하기

개발자팁

개발과 관련된 유용한 정보를 공유하세요.
질문은 QA에서 해주시기 바랍니다.
번호 분류 제목 글쓴이 날짜 조회
5402 MySQL 6일 전 조회 21
5401 JavaScript 2주 전 조회 115
5400 MySQL 1개월 전 조회 222
5399 PHP 2개월 전 조회 468
5398 PHP 2개월 전 조회 353
5397 PHP 2개월 전 조회 282
5396 기타 5개월 전 조회 559
5395 PHP 6개월 전 조회 1,196
5394 MySQL 7개월 전 조회 790
5393 웹서버 9개월 전 조회 985
5392 1년 전 조회 1,309
5391 11개월 전 조회 1,319
5390 11개월 전 조회 1,114
5389 10개월 전 조회 1,029
5388 10개월 전 조회 1,170
5387 9개월 전 조회 962
5386 JavaScript 9개월 전 조회 1,148
5385 웹서버 9개월 전 조회 1,169
5384 JavaScript 10개월 전 조회 991
5383 기타 11개월 전 조회 1,415
5382 기타 11개월 전 조회 659
5381 JavaScript 11개월 전 조회 1,074
5380 기타 11개월 전 조회 833
5379 JavaScript 11개월 전 조회 831
5378 1년 전 조회 1,396
5377 기타 1년 전 조회 941
5376 jQuery 1년 전 조회 639
5375 jQuery 1년 전 조회 871
5374 기타 1년 전 조회 947
5373 MySQL 1년 전 조회 980
🐛 버그신고