Created
August 24, 2014 02:10
-
-
Save codescribblr/d6ff2f73e2e5161e8869 to your computer and use it in GitHub Desktop.
Using bit.ly v3 api to shorten a url with php.
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
| /* make a URL small */ | |
| function make_bitly_url($url,$access_token) { | |
| //create the URL | |
| $bitly = 'http://api-ssl.bitly.com/v3/shorten?access_token='.$access_token.'&longUrl='.urlencode($url); | |
| //get the url | |
| //could also use cURL here | |
| $response = file_get_contents($bitly); | |
| $json = @json_decode($response,true); | |
| return $json['results'][$url]['shortUrl']; | |
| } | |
| /* usage */ | |
| $short = make_bitly_url('http://codescribblr.com','b39e7e013a89e3b836372728e3370b80dd6c6bac'); | |
| echo 'The short URL is: '.$short; | |
| // returns: http://bit.ly/11Owun |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment