Skip to content

Instantly share code, notes, and snippets.

@ytkhs
Created January 15, 2011 15:07
Show Gist options
  • Save ytkhs/780964 to your computer and use it in GitHub Desktop.
Save ytkhs/780964 to your computer and use it in GitHub Desktop.
Examples to get shorten or decode target url using bit.ly.
<?php
define('LOGIN', 'xxxxx');
define('API_KEY', 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
define('END_POINT', 'http://api.bit.ly/v3');
function getShortUrl($longUrl)
{
$query = http_build_query(
array(
'login' => LOGIN,
'apiKey' => API_KEY,
'longUrl' => $longUrl,
'format' => 'txt'
#'domain' => 'j.mp'
)
);
return file_get_contents(sprintf('%s/%s?%s', END_POINT, 'shorten', $query));
}
function getLongUrl($shortUrl)
{
$query = http_build_query(
array(
'login' => LOGIN,
'apiKey' => API_KEY,
'shortUrl' => $shortUrl,
'format' => 'txt'
)
);
return file_get_contents(sprintf('%s/%s?%s', END_POINT, 'expand', $query));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment