php 谷歌짧은주소만들기
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 谷歌짧은주소만들기相关的知识,希望对你有一定的参考价值。
// goo.gl 짧은주소 만들기
function googl_short_url($longUrl)
{
global $config;
// Get API key from : http://code.google.com/apis/console/
// URL Shortener API ON
$apiKey = $config['cf_googl_shorturl_apikey'];
$postData = array('longUrl' => $longUrl);
$jsonData = json_encode($postData);
$curlObj = curl_init();
curl_setopt($curlObj, CURLOPT_URL, 'https://www.googleapis.com/urlshortener/v1/url?key='.$apiKey);
curl_setopt($curlObj, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curlObj, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curlObj, CURLOPT_HEADER, 0);
curl_setopt($curlObj, CURLOPT_HTTPHEADER, array('Content-type:application/json'));
curl_setopt($curlObj, CURLOPT_POST, 1);
curl_setopt($curlObj, CURLOPT_POSTFIELDS, $jsonData);
$response = curl_exec($curlObj);
//change the response json string to object
$json = json_decode($response);
curl_close($curlObj);
return $json->id;
}
以上是关于php 谷歌짧은주소만들기的主要内容,如果未能解决你的问题,请参考以下文章