[email protected] Posted December 6, 2009 Share Posted December 6, 2009 I am trying to shorten my link using bit.ly API. If someone has idea of using curl and using this API, please let me know $host = "http://api.bit.ly/shorten?version=2.0.1&longUrl=http://www.ideatoceo.com"; var_dump($host); I am not properly calling the API or not using curl...please help Link to comment https://forums.phpfreaks.com/topic/184205-using-curl-for-bitly/ Share on other sites More sharing options...
oni-kun Posted December 6, 2009 Share Posted December 6, 2009 You don't need curl.. but you're not even pulling the data from it. $url = file_get_contents('http://api.bit.ly/shorten?version=2.0.1&longUrl=http://www.ideatoceo.com'); json_decode($url); //Or whatever API specifies.. Link to comment https://forums.phpfreaks.com/topic/184205-using-curl-for-bitly/#findComment-972517 Share on other sites More sharing options...
[email protected] Posted December 6, 2009 Author Share Posted December 6, 2009 I am getting "parse" error while using this code <?php $longurl = "http://advertise.ideatoceo.com"; public function get_bitly_shorturl($longurl) { //getting parse error here $url = "http://api.bit.ly/shorten?" . "version=2.0.1&login=XXXX&apiKey=XXXX" . "&format=json&history=1" . "&longUrl=".urlencode($longurl); $page = file_get_contents($url); $result = json_decode($page); return $result->{'results'}->{$longurl}->{'shortUrl'}; } ?> Link to comment https://forums.phpfreaks.com/topic/184205-using-curl-for-bitly/#findComment-972524 Share on other sites More sharing options...
salathe Posted December 6, 2009 Share Posted December 6, 2009 The visibility keywords (public in your code) are only available within class definitions, not for functions. Link to comment https://forums.phpfreaks.com/topic/184205-using-curl-for-bitly/#findComment-972526 Share on other sites More sharing options...
[email protected] Posted December 6, 2009 Author Share Posted December 6, 2009 I removed public but there is no output. <?php $longurl = "http://advertise.ideatoceo.com"; function get_bitly_shorturl($longurl) { //getting parse error here $url = "http://api.bit.ly/shorten?" . "version=2.0.1&login=XXXX&apiKey=XXXX" . "&format=json&history=1" . "&longUrl=".urlencode($longurl); $page = file_get_contents($url); $result = json_decode($page); return $result->{'results'}->{$longurl}->{'shortUrl'}; } ?> Link to comment https://forums.phpfreaks.com/topic/184205-using-curl-for-bitly/#findComment-972534 Share on other sites More sharing options...
salathe Posted December 6, 2009 Share Posted December 6, 2009 You're not calling the function. Link to comment https://forums.phpfreaks.com/topic/184205-using-curl-for-bitly/#findComment-972538 Share on other sites More sharing options...
oni-kun Posted December 6, 2009 Share Posted December 6, 2009 I removed public but there is no output. <?php $longurl = "http://advertise.ideatoceo.com"; function get_bitly_shorturl($longurl) { //getting parse error here $url = "http://api.bit.ly/shorten?" . "version=2.0.1&login=XXXX&apiKey=XXXX" . "&format=json&history=1" . "&longUrl=".urlencode($longurl); $page = file_get_contents($url); $result = json_decode($page); return $result->{'results'}->{$longurl}->{'shortUrl'}; } echo get_bitly_shorturl($longurl); //Done! ?> Link to comment https://forums.phpfreaks.com/topic/184205-using-curl-for-bitly/#findComment-972541 Share on other sites More sharing options...
[email protected] Posted December 6, 2009 Author Share Posted December 6, 2009 Thanks !! Link to comment https://forums.phpfreaks.com/topic/184205-using-curl-for-bitly/#findComment-972549 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.