테스트 사이트 - 개발 중인 베타 버전입니다

구글 짧은 주소 API활용방법 문의드립니다. 채택완료

더블피디 9년 전 조회 9,856

 

간단하게 사용하려면,

https://goo.gl/">https://goo.gl/ 접속 후  입력하고 나면 원하는 웹페이지의 url을 입력하면 아래와 같이 링크 주소를 보여주는데

아래와 같이 알려준 주소를 사용하면 간단하네요

 


 

 

관리자페이지 하단에 

아래와 같이 구글 짧은 주소 API key입력 하는 부분이 있구요.

 

http://sir.kr/data/editor/1605/340a446f374175743aa895606ffaf0b3_1462315237_3067.png" title="340a446f374175743aa895606ffaf0b3_1462315237_3067.png"> 

버튼을 누르면 https://console.developers.google.com/apis/library">https://console.developers.google.com/apis/library API 라이브러리 페이지가 열립니다.


짧은url 관련한 API는 아래 주소로 가야할듯구요

https://console.developers.google.com/apis/api/urlshortener/overview">https://console.developers.google.com/apis/api/urlshortener/overview 

 

구글 URL API이라고하는데요

</pre><pre style="line-height: normal;"><span style="font-family: 돋움; font-size: 14.6667px; white-space: normal;"><!--?php </span>
</pre><pre style="line-height: normal;">function get_shortURL($longURL) {
	$api_key = "구글 API 키값";      
	$curlopt_url = "<a href="https://www.googleapis.com/urlshortener/v1/url?key=" target="_blank" rel="noopener noreferrer">https://www.googleapis.com/urlshortener/v1/url?key=</a>".$api_key;      

	$ch = curl_init();  
	//$timeout = 10;    
	curl_setopt($ch, CURLOPT_URL, $curlopt_url);  
	curl_setopt($ch, CURLOPT_HEADER, false);  
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);  
	//curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
 
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);    
	curl_setopt($ch, CURLOPT_POST, true);     
	curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));     
	$jsonArray = array('longUrl' =--> $longURL);     
	curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($jsonArray));     
	$shortURL = curl_exec($ch);    curl_close($ch);    
	$result_array = json_decode($shortURL, true);    
	

	return $result_array['id']; // goo.gl    
	
	$shortURL = curl_exec($ch);  
	curl_close($ch);  
	return $shortURL;
}	
?></pre><p style="font-size: 14.6667px;">

 

이걸 그누보드와 어떻게 연동해서 사용하는건지?

 

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

답변 2개

채택된 답변
+20 포인트
9년 전

<?

$long = "http://www.naver.com">www.naver.com";

$shot = get_shortURL($long);


?>

로그인 후 평가할 수 있습니다

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

7년 전

구글 단축 URL API 사용방법 (Javascript) :
https://goo.gl/hU42mG">https://goo.gl/hU42mG

로그인 후 평가할 수 있습니다

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

답변을 작성하려면 로그인이 필요합니다.

로그인