구글 단축 주소

· 9년 전 · 3664 · 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,328
PHP 9년 전 조회 1,962
PHP 9년 전 조회 2,235
PHP 9년 전 조회 2,637
PHP 9년 전 조회 2,442
PHP 9년 전 조회 1,998
PHP 9년 전 조회 2,265
PHP 9년 전 조회 2,187
PHP 9년 전 조회 2,471
PHP 9년 전 조회 2,226
PHP 9년 전 조회 2,083
PHP 9년 전 조회 2,114
PHP 9년 전 조회 1,850
PHP 9년 전 조회 1,949
PHP 9년 전 조회 3,665
PHP 9년 전 조회 4,250
PHP 9년 전 조회 2,916
PHP 9년 전 조회 2,301
PHP 9년 전 조회 4,199
PHP 9년 전 조회 2,331
PHP 9년 전 조회 2,122
PHP 9년 전 조회 4,532
PHP 9년 전 조회 2,799
PHP 9년 전 조회 2,105
PHP 9년 전 조회 2,568
PHP 9년 전 조회 2,244
PHP 9년 전 조회 2,673
PHP 9년 전 조회 2,164
PHP 9년 전 조회 2,549
PHP 9년 전 조회 2,253
🐛 버그신고