goo.gl shortener api

https://developers.google.com/url-shortener/v1/getting_started

OAuth 2.0で使えるようです。
or apikey
or 何も無し。

とりあえず。何も無しで使ってみます。

$api = ‘https://www.googleapis.com/urlshortener/v1/url';

$post_data = json_encode(array(‘longUrl’ => $url ));
curl_setopt($ch, CURLOPT_URL, $api );
curl_setopt($ch,CURLOPT_HTTPHEADER,array (“Content-Type: application/json” ));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 2);
$json = curl_exec($ch);
curl_close($ch);

jsonデータをpostするだけです。

{
“kind”: “urlshortener#url”,
“id”: “http://goo.gl/xSJmh”,
“longUrl”: “http://blog.bbtune.com/”
}

無事、こんなデータが。

で戻すときは

Expand a short URL

https://www.googleapis.com/urlshortener/v1/url?shortUrl=http://goo.gl/xSJmh

{
“kind”: “urlshortener#url”,
“id”: “http://goo.gl/xSJmh”,
“longUrl”: “http://blog.bbtune.com/”,
“status”: “OK”
}

This entry was posted on 火曜日, 7月 10th, 2012 at 11:29 PM and is filed under Google. You can follow any responses to this entry through the RSS 2.0 feed. Both comments and pings are currently closed.

Unityによるゲームを公開しております iOS/Android
https://itunes.apple.com/jp/app/lost-knight-3d-action/id900917032
https://play.google.com/store/apps/details?id=com.groundroad.runknight

各種開発支援・機能開発等小さいお仕事などもお請けしております。
unity開発支援, PHPシステム開発, javascript/html5 フロント開発, titanium mobileアプリ開発
お気軽にお問い合わせください
大崎・五反田近郊での対面でのお打ち合わせはいつでも可能です。