구글 단축 주소

· 9년 전 · 3670 · 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,333
PHP 9년 전 조회 1,965
PHP 9년 전 조회 2,237
PHP 9년 전 조회 2,641
PHP 9년 전 조회 2,446
PHP 9년 전 조회 2,004
PHP 9년 전 조회 2,269
PHP 9년 전 조회 2,190
PHP 9년 전 조회 2,474
PHP 9년 전 조회 2,229
PHP 9년 전 조회 2,086
PHP 9년 전 조회 2,117
PHP 9년 전 조회 1,854
PHP 9년 전 조회 1,954
PHP 9년 전 조회 3,671
PHP 9년 전 조회 4,255
PHP 9년 전 조회 2,920
PHP 9년 전 조회 2,302
PHP 9년 전 조회 4,203
PHP 9년 전 조회 2,333
PHP 9년 전 조회 2,126
PHP 9년 전 조회 4,538
PHP 9년 전 조회 2,804
PHP 9년 전 조회 2,111
PHP 9년 전 조회 2,569
PHP 9년 전 조회 2,251
PHP 9년 전 조회 2,676
PHP 9년 전 조회 2,170
PHP 9년 전 조회 2,553
PHP 9년 전 조회 2,257
🐛 버그신고