구글 단축 주소
[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개