缩短goo.gl公司

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了缩短goo.gl公司相关的知识,希望对你有一定的参考价值。

I needed a simple function to shorten a link with goo.gl and wrote this, thought it may help someone. Note: you still need an API key from goo.gl
  1. function getgoogl($glurl, $apikey) {
  2.  
  3. $userurl = rawurlencode($glurl);
  4.  
  5. $ch = curl_init('https://www.googleapis.com/urlshortener/v1/url?key='.$apikey);
  6. CURLOPT_POST => TRUE,
  7. CURLOPT_RETURNTRANSFER => TRUE,
  8. CURLOPT_HTTPHEADER => array('Content-type: application/json'),
  9. CURLOPT_POSTFIELDS => json_encode(array('longUrl' => $userurl))
  10. ));
  11. $chresults = json_decode(curl_exec($ch));
  12. curl_close($ch);
  13.  
  14. return $chresults->id;
  15. }

以上是关于缩短goo.gl公司的主要内容,如果未能解决你的问题,请参考以下文章