구글 단축 주소

· 9년 전 · 3715 · 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에서 해주시기 바랍니다.

+
분류 제목 글쓴이 날짜 조회
PHP 9년 전 조회 2,351
PHP 9년 전 조회 1,993
PHP 9년 전 조회 2,268
PHP 9년 전 조회 2,672
PHP 9년 전 조회 2,479
PHP 9년 전 조회 2,022
PHP 9년 전 조회 2,295
PHP 9년 전 조회 2,226
PHP 9년 전 조회 2,514
PHP 9년 전 조회 2,273
PHP 9년 전 조회 2,119
PHP 9년 전 조회 2,161
PHP 9년 전 조회 1,891
PHP 9년 전 조회 1,999
PHP 9년 전 조회 3,716
PHP 9년 전 조회 4,273
PHP 9년 전 조회 2,960
PHP 9년 전 조회 2,315
PHP 9년 전 조회 4,225
PHP 9년 전 조회 2,370
PHP 9년 전 조회 2,160
PHP 9년 전 조회 4,569
PHP 9년 전 조회 2,837
PHP 9년 전 조회 2,143
PHP 9년 전 조회 2,581
PHP 9년 전 조회 2,285
PHP 9년 전 조회 2,690
PHP 9년 전 조회 2,189
PHP 9년 전 조회 2,577
PHP 9년 전 조회 2,280
🐛 버그신고