Created
January 15, 2011 15:07
-
-
Save ytkhs/780964 to your computer and use it in GitHub Desktop.
Examples to get shorten or decode target url using bit.ly.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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